Submission #1311240
Source Code Expand
#include <bits/stdc++.h> using namespace std; int R, C, Q; char g[2005][2005]; int p[2005][2005], h[2005][2005], v[2005][2005]; int main() { scanf("%d%d%d", &R, &C, &Q); for (int i = 0; i < R; i++) scanf("%s", &g[i]); for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { if (g[i][j] == '1') p[i][j]++; if (j + 1 < C) { if (g[i][j] == '1' && g[i][j + 1] == '1') h[i][j]++; } if (i + 1 < R) if (g[i][j] == '1' && g[i + 1][j] == '1') v[i][j]++; } } for (int i = 0; i < R; i++) { for (int j = 1; j < C; j++) { h[i][j] += h[i][j - 1]; p[i][j] += p[i][j - 1]; v[i][j] += v[i][j - 1]; } } for (int i = 1; i < R; i++) { for (int j = 0; j < C; j++) { h[i][j] += h[i - 1][j]; p[i][j] += p[i - 1][j]; v[i][j] += v[i - 1][j]; } } while (Q--) { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); a--; b--; c--; d--; int ans = p[c][d] - ((a == 0) ? 0 : p[a - 1][d]) - ((b == 0) ? 0 : p[c][b - 1]) + ((a == 0 || b == 0) ? 0 : p[a - 1][b - 1]); ans -= ((d == 0) ? 0 : h[c][d - 1]) - ((a == 0 || d == 0) ? 0 : h[a - 1][d - 1]) - ((b == 0) ? 0 : h[c][b - 1]) + ((a == 0 || b == 0) ? 0 : h[a - 1][b - 1]); ans -= ((c == 0) ? 0 : v[c - 1][d]) - ((a == 0) ? 0 : v[a - 1][d]) - ((b == 0 || c == 0) ? 0 : v[c - 1][b - 1]) + ((a == 0 || b == 0) ? 0 : v[a - 1][b - 1]); printf("%d\n", ans); } }
Submission Info
Submission Time | |
---|---|
Task | C - Nuske vs Phantom Thnook |
User | pwypeanut |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1401 Byte |
Status | AC |
Exec Time | 162 ms |
Memory | 52864 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:10:47: warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘char (*)[2005]’ [-Wformat=] for (int i = 0; i < R; i++) scanf("%s", &g[i]); ^ ./Main.cpp:9:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d%d", &R, &C, &Q); ^ ./Main.cpp:10:48: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] for (int i = 0; i < R; i++) scanf("%s", &g[i]); ^ ./Main.cpp:36:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d%d%d", &a, &b, &c, &d); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, s1.txt, s2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 138 ms | 52480 KB |
02.txt | AC | 162 ms | 52352 KB |
03.txt | AC | 138 ms | 52480 KB |
04.txt | AC | 159 ms | 52224 KB |
05.txt | AC | 139 ms | 52608 KB |
06.txt | AC | 161 ms | 52352 KB |
07.txt | AC | 114 ms | 52224 KB |
08.txt | AC | 143 ms | 52224 KB |
09.txt | AC | 131 ms | 52224 KB |
10.txt | AC | 160 ms | 52224 KB |
11.txt | AC | 138 ms | 52480 KB |
12.txt | AC | 111 ms | 34048 KB |
13.txt | AC | 82 ms | 51072 KB |
14.txt | AC | 75 ms | 7296 KB |
15.txt | AC | 66 ms | 4736 KB |
16.txt | AC | 77 ms | 7040 KB |
17.txt | AC | 81 ms | 51072 KB |
18.txt | AC | 81 ms | 50688 KB |
19.txt | AC | 71 ms | 7168 KB |
20.txt | AC | 133 ms | 51328 KB |
21.txt | AC | 114 ms | 51840 KB |
22.txt | AC | 160 ms | 52224 KB |
23.txt | AC | 77 ms | 12160 KB |
24.txt | AC | 161 ms | 52224 KB |
25.txt | AC | 70 ms | 6784 KB |
26.txt | AC | 73 ms | 9472 KB |
27.txt | AC | 70 ms | 7040 KB |
28.txt | AC | 81 ms | 50688 KB |
29.txt | AC | 82 ms | 51072 KB |
30.txt | AC | 75 ms | 7040 KB |
31.txt | AC | 120 ms | 52864 KB |
32.txt | AC | 144 ms | 52480 KB |
33.txt | AC | 119 ms | 52224 KB |
34.txt | AC | 144 ms | 52480 KB |
35.txt | AC | 118 ms | 52096 KB |
36.txt | AC | 142 ms | 51968 KB |
37.txt | AC | 118 ms | 52096 KB |
38.txt | AC | 139 ms | 51968 KB |
39.txt | AC | 117 ms | 52608 KB |
40.txt | AC | 141 ms | 52480 KB |
41.txt | AC | 125 ms | 52224 KB |
42.txt | AC | 142 ms | 52096 KB |
43.txt | AC | 117 ms | 51712 KB |
44.txt | AC | 143 ms | 51840 KB |
45.txt | AC | 2 ms | 2304 KB |
46.txt | AC | 2 ms | 6400 KB |
47.txt | AC | 2 ms | 6400 KB |
48.txt | AC | 2 ms | 6400 KB |
s1.txt | AC | 2 ms | 6400 KB |
s2.txt | AC | 2 ms | 6400 KB |