Submission #1653799
Source Code Expand
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;
template <class T> class CumulativeSum2D {
public:
vector<vector<T>> s;
int h, w;
CumulativeSum2D(const vector<vector<T>> &a) {
h = a.size();
w = a[0].size();
s = vector<vector<T>>(h + 1, vector<T>(w + 1, 0));
rep(i, h) rep(j, w) s[i + 1][j + 1] = a[i][j];
rep(i, h + 1) rep(j, w) s[i][j + 1] += s[i][j];
rep(i, h) rep(j, w + 1) s[i + 1][j] += s[i][j];
}
int sum(int i, int j, int h, int w) {
return s[i + h][j + w] - s[i][j + w] + s[i][j] - s[i + h][j];
}
int maximumSubMatrix(){
int ret = -INF;
rep(i,h + 1) rep(j,w + 1) range(k,1,h - i + 1) range(l,1,w - j + 1){
ret = max(ret, sum(i,j,k,l));
}
return ret;
}
void output(){
rep(i,h + 1){
rep(j,w + 1){
cout << s[i][j] << ' ';
}
cout << endl;
}
}
};
int main(){
int n, m, q;
cin >> n >> m >> q;
vector<vector<int>> va(n, vector<int>(m,0));
rep(i,n){
rep(j,m){
char a;
cin >> a;
va[i][j] = a - '0';
}
}
vector<vector<int>> hol(n, vector<int>(m,0));
vector<vector<int>> var(n, vector<int>(m,0));
rep(i,n - 1){
rep(j,m){
if(va[i][j] && va[i + 1][j]) var[i][j] = 1;
//cout << var[i][j];
}
//cout << endl;
}
rep(i,n){
rep(j,m - 1){
if(va[i][j] && va[i][j + 1]) hol[i][j] = 1;
//cout << hol[i][j];
}
//cout << endl;
}
CumulativeSum2D<int> s(va), h(hol), v(var);
//v.output();
//h.output();
rep(i,q){
int a, b, c, d;
cin >> a >> b >> c >> d;
a--; b--; c--; d--;
//show(s.sum(a,b,c - a + 1,d - b + 1))
//show(h.sum(a,b,c - a + 1,d - b))
//show(v.sum(a,b,c - a,d - b + 1))
cout << s.sum(a,b,c - a + 1,d - b + 1) -
h.sum(a,b,c - a + 1,d - b) -
v.sum(a,b,c - a,d - b + 1) << endl;
}
}
Submission Info
Submission Time |
|
Task |
C - Nuske vs Phantom Thnook |
User |
noy72 |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
2033 Byte |
Status |
AC |
Exec Time |
937 ms |
Memory |
96896 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 |
858 ms |
95616 KB |
02.txt |
AC |
928 ms |
95616 KB |
03.txt |
AC |
857 ms |
95488 KB |
04.txt |
AC |
924 ms |
94976 KB |
05.txt |
AC |
872 ms |
95872 KB |
06.txt |
AC |
922 ms |
95488 KB |
07.txt |
AC |
806 ms |
90752 KB |
08.txt |
AC |
905 ms |
91648 KB |
09.txt |
AC |
822 ms |
82304 KB |
10.txt |
AC |
937 ms |
95488 KB |
11.txt |
AC |
862 ms |
95616 KB |
12.txt |
AC |
682 ms |
34944 KB |
13.txt |
AC |
483 ms |
1920 KB |
14.txt |
AC |
489 ms |
1408 KB |
15.txt |
AC |
453 ms |
640 KB |
16.txt |
AC |
489 ms |
1024 KB |
17.txt |
AC |
480 ms |
1664 KB |
18.txt |
AC |
497 ms |
1280 KB |
19.txt |
AC |
490 ms |
1152 KB |
20.txt |
AC |
884 ms |
85504 KB |
21.txt |
AC |
858 ms |
95104 KB |
22.txt |
AC |
934 ms |
95488 KB |
23.txt |
AC |
496 ms |
1920 KB |
24.txt |
AC |
932 ms |
95488 KB |
25.txt |
AC |
455 ms |
640 KB |
26.txt |
AC |
472 ms |
1024 KB |
27.txt |
AC |
487 ms |
896 KB |
28.txt |
AC |
493 ms |
1280 KB |
29.txt |
AC |
481 ms |
1664 KB |
30.txt |
AC |
486 ms |
1024 KB |
31.txt |
AC |
862 ms |
96000 KB |
32.txt |
AC |
917 ms |
95744 KB |
33.txt |
AC |
828 ms |
96896 KB |
34.txt |
AC |
916 ms |
95744 KB |
35.txt |
AC |
830 ms |
95232 KB |
36.txt |
AC |
908 ms |
95232 KB |
37.txt |
AC |
827 ms |
95232 KB |
38.txt |
AC |
895 ms |
95232 KB |
39.txt |
AC |
837 ms |
95872 KB |
40.txt |
AC |
903 ms |
95744 KB |
41.txt |
AC |
829 ms |
95488 KB |
42.txt |
AC |
879 ms |
95232 KB |
43.txt |
AC |
829 ms |
94848 KB |
44.txt |
AC |
902 ms |
95104 KB |
45.txt |
AC |
1 ms |
256 KB |
46.txt |
AC |
1 ms |
256 KB |
47.txt |
AC |
1 ms |
256 KB |
48.txt |
AC |
1 ms |
256 KB |
s1.txt |
AC |
1 ms |
256 KB |
s2.txt |
AC |
1 ms |
256 KB |