Submission #1758176
Source Code Expand
#include <iostream> #include <fstream> #include <sstream> #include <vector> #include <string> #include <algorithm> #include <queue> #include <stack> #include <map> #include <set> #include <unordered_set> #include <unordered_map> #include <bitset> #include <limits> #include <random> #include <complex> #include <cmath> #include <cstdio> #include <cstdlib> #include <string.h> #include <iomanip> using namespace std; #define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++) #define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--) #define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end()) typedef long long ll; int N,M,Q; char S[2010][2010]; int V[2010][2010]; int X[2010][2010]; int Y[2010][2010]; int cnt_ver(int x1, int y1, int x2, int y2) { x1--; y1--; return V[y2][x2] - V[y2][x1] - V[y1][x2] + V[y1][x1]; } int cnt_edge(int x1, int y1, int x2, int y2) { x1--; y1--; int a = X[y2][x2] - X[y2][x1 + 1] - X[y1][x2] + X[y1][x1 + 1]; int b = Y[y2][x2] - Y[y2][x1] - Y[y1 + 1][x2] + Y[y1 + 1][x1]; return a + b; } int main() { cin >> N >> M >> Q; vector < string > St(N); REP(i,N) cin >> St[i]; REP(i,N) REP(j,M) S[i + 1][j + 1] = St[i][j]; REP(i,N) REP(j,M) V[i + 1][j + 1] = S[i + 1][j + 1] - '0'; N += 2; M += 2; REP(i,N) REP(j,M) V[i + 1][j] = V[i + 1][j] + V[i][j]; REP(i,N) REP(j,M) V[i][j + 1] = V[i][j + 1] + V[i][j]; for (int i = 2; i <= N; i++) { for (int j = 1; j <= M; j++) { if (S[i][j] == '1' && S[i - 1][j] == '1') Y[i][j] = 1; } } REP(i,N) REP(j,M) Y[i + 1][j] = Y[i + 1][j] + Y[i][j]; REP(i,N) REP(j,M) Y[i][j + 1] = Y[i][j + 1] + Y[i][j]; for (int i = 1; i <= N; i++) { for (int j = 2; j <= M; j++) { if (S[i][j] == '1' && S[i][j - 1] == '1') X[i][j] = 1; } } REP(i,N) REP(j,M) X[i + 1][j] = X[i + 1][j] + X[i][j]; REP(i,N) REP(j,M) X[i][j + 1] = X[i][j + 1] + X[i][j]; REP(i,Q) { int x1,y1,x2,y2; cin >> y1 >> x1 >> y2 >> x2; cout << cnt_ver(x1, y1, x2, y2) - cnt_edge(x1, y1, x2, y2) << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Nuske vs Phantom Thnook |
User | kosakkun |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 2219 Byte |
Status | AC |
Exec Time | 859 ms |
Memory | 57216 KB |
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 | 713 ms | 56832 KB |
02.txt | AC | 733 ms | 56704 KB |
03.txt | AC | 697 ms | 56832 KB |
04.txt | AC | 740 ms | 56576 KB |
05.txt | AC | 707 ms | 56960 KB |
06.txt | AC | 735 ms | 56704 KB |
07.txt | AC | 656 ms | 56576 KB |
08.txt | AC | 697 ms | 56448 KB |
09.txt | AC | 672 ms | 56576 KB |
10.txt | AC | 734 ms | 56576 KB |
11.txt | AC | 859 ms | 56960 KB |
12.txt | AC | 594 ms | 38144 KB |
13.txt | AC | 485 ms | 51456 KB |
14.txt | AC | 483 ms | 7296 KB |
15.txt | AC | 441 ms | 6784 KB |
16.txt | AC | 487 ms | 7040 KB |
17.txt | AC | 496 ms | 51456 KB |
18.txt | AC | 501 ms | 51072 KB |
19.txt | AC | 497 ms | 7168 KB |
20.txt | AC | 682 ms | 55552 KB |
21.txt | AC | 676 ms | 56192 KB |
22.txt | AC | 734 ms | 56576 KB |
23.txt | AC | 498 ms | 12288 KB |
24.txt | AC | 742 ms | 56576 KB |
25.txt | AC | 440 ms | 6784 KB |
26.txt | AC | 482 ms | 9472 KB |
27.txt | AC | 487 ms | 7040 KB |
28.txt | AC | 496 ms | 51072 KB |
29.txt | AC | 489 ms | 51456 KB |
30.txt | AC | 493 ms | 7168 KB |
31.txt | AC | 666 ms | 57216 KB |
32.txt | AC | 711 ms | 56960 KB |
33.txt | AC | 681 ms | 56576 KB |
34.txt | AC | 705 ms | 56832 KB |
35.txt | AC | 662 ms | 56448 KB |
36.txt | AC | 705 ms | 56320 KB |
37.txt | AC | 670 ms | 56448 KB |
38.txt | AC | 689 ms | 56320 KB |
39.txt | AC | 681 ms | 56960 KB |
40.txt | AC | 699 ms | 56832 KB |
41.txt | AC | 677 ms | 56576 KB |
42.txt | AC | 702 ms | 56448 KB |
43.txt | AC | 667 ms | 56064 KB |
44.txt | AC | 714 ms | 56192 KB |
45.txt | AC | 2 ms | 6400 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 |