Submission #1772076
Source Code Expand
#include <iostream> #include <cstdio> #include <climits> #include <algorithm> #include <queue> #include <cstring> #include <cmath> #include <vector> #include <list> #include <stack> #include <bitset> #include <string> #include <stack> #include <set> #include <map> #include <string> #include <deque> #include <ctime> #define s(n) scanf("%d",&n) #define sl(n) scanf("%lld",&n) #define ss(n) scanf("%s",n) #define s2(a,b) scanf("%d%d",&a,&b) #define SET(p) memset(p,-1,sizeof(p)) #define CLR(p) memset(p,0,sizeof(p)) #define vi vector<int> #define ii pair<int,int> #define pb push_back #define mp make_pair #define F first #define S second #define LL long long #define ULL unsigned long long #define R freopen("in","r",stdin) #define W freopen("out","w",stdout) using namespace std; vector<vector<int> > arr; vector<vector<int> > hor; vector<vector<int> > ver; int main() { int n,m,q; cin>>n>>m>>q; arr.resize(n,vector<int>(m,0)); hor.resize(n,vector<int>(m,0)); ver.resize(n,vector<int>(m,0)); char str[m+1]; for(int i=0;i<n;i++){ ss(str); for(int j=0;j<m;j++){ arr[i][j]=(int)(str[j] - '0'); if(j>0){ hor[i][j] += (arr[i][j]&&arr[i][j-1]); } if(i>0){ ver[i][j] += (arr[i][j]&&arr[i-1][j]); } } } for(int i=0;i<n;i++) { for(int j=1;j<m;j++){ arr[i][j] += (arr[i][j-1]); hor[i][j] += (hor[i][j-1]); ver[i][j] += (ver[i][j-1]); } } for(int i=1;i<n;i++) { for(int j=0;j<m;j++){ arr[i][j] += (arr[i-1][j]); hor[i][j] += (hor[i-1][j]); ver[i][j] += (ver[i-1][j]); } } // for(int i=0;i<n;i++){ // for (int j=0;j<m;j++){ // cout<<arr[i][j]<<" "; // } // cout<<endl; // } // cout<<endl; // for(int i=0;i<n;i++){ // for (int j=0;j<m;j++){ // cout<<hor[i][j]<<" "; // } // cout<<endl; // } // cout<<endl; // for(int i=0;i<n;i++){ // for (int j=0;j<m;j++){ // cout<<ver[i][j]<<" "; // } // cout<<endl; // } // cout<<endl; int x1,x2,y1,y2; for(int i=0;i<q;i++){ int ans = 0; s2(x1,y1); s2(x2,y2); x1--;y1--;x2--;y2--; ans += arr[x2][y2]; if(x1 > 0){ ans -= arr[x1-1][y2]; } if(y1 > 0){ ans -= arr[x2][y1-1]; } if(x1>0 && y1>0) { ans += arr[x1-1][y1-1]; } // cout<<ans<<endl; y1++; if(y2>=y1){ ans -= hor[x2][y2]; if(x1 > 0){ ans += hor[x1-1][y2]; } if(y1 > 0){ ans += hor[x2][y1-1]; } if(x1>0 && y1>0) { ans -= hor[x1-1][y1-1]; } } y1--; // printf("%d\n", ans); x1++; // cout<<x1<<" "<<x2<<" "<<y1<<" "<<y2<<endl; if(x2>=x1){ ans -= ver[x2][y2]; // cout<<ver[x2][y2]; if(x1 > 0){ ans += ver[x1-1][y2]; // cout<<ver[x1-1][y2]; } if(y1 > 0){ ans += ver[x2][y1-1]; // cout<<ver[x2][y1-1]; } if(x1>0 && y1>0) { ans -= ver[x1-1][y1-1]; // cout<<ver[x1-1][y1-1]; } } printf("%d\n", ans); } }
Submission Info
Submission Time | |
---|---|
Task | C - Nuske vs Phantom Thnook |
User | aman1893 |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 3007 Byte |
Status | AC |
Exec Time | 219 ms |
Memory | 49664 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:51:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] ss(str); ^ ./Main.cpp:109:12: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] s2(x1,y1); ^ ./Main.cpp:110:12: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] s2(x2,y2); ^
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 | 170 ms | 48512 KB |
02.txt | AC | 219 ms | 48384 KB |
03.txt | AC | 166 ms | 48384 KB |
04.txt | AC | 219 ms | 48000 KB |
05.txt | AC | 173 ms | 48768 KB |
06.txt | AC | 218 ms | 48384 KB |
07.txt | AC | 149 ms | 45952 KB |
08.txt | AC | 203 ms | 46464 KB |
09.txt | AC | 157 ms | 41856 KB |
10.txt | AC | 215 ms | 48256 KB |
11.txt | AC | 166 ms | 48512 KB |
12.txt | AC | 133 ms | 18048 KB |
13.txt | AC | 78 ms | 1408 KB |
14.txt | AC | 78 ms | 1152 KB |
15.txt | AC | 69 ms | 640 KB |
16.txt | AC | 77 ms | 896 KB |
17.txt | AC | 76 ms | 1408 KB |
18.txt | AC | 76 ms | 1024 KB |
19.txt | AC | 74 ms | 1024 KB |
20.txt | AC | 191 ms | 43008 KB |
21.txt | AC | 151 ms | 48000 KB |
22.txt | AC | 216 ms | 48384 KB |
23.txt | AC | 80 ms | 1408 KB |
24.txt | AC | 215 ms | 48384 KB |
25.txt | AC | 71 ms | 640 KB |
26.txt | AC | 74 ms | 896 KB |
27.txt | AC | 73 ms | 896 KB |
28.txt | AC | 77 ms | 1024 KB |
29.txt | AC | 76 ms | 1408 KB |
30.txt | AC | 78 ms | 1024 KB |
31.txt | AC | 159 ms | 49024 KB |
32.txt | AC | 208 ms | 48640 KB |
33.txt | AC | 154 ms | 48384 KB |
34.txt | AC | 205 ms | 48640 KB |
35.txt | AC | 153 ms | 48128 KB |
36.txt | AC | 202 ms | 48128 KB |
37.txt | AC | 153 ms | 48128 KB |
38.txt | AC | 202 ms | 48128 KB |
39.txt | AC | 155 ms | 48768 KB |
40.txt | AC | 219 ms | 48512 KB |
41.txt | AC | 157 ms | 48384 KB |
42.txt | AC | 202 ms | 49664 KB |
43.txt | AC | 151 ms | 47744 KB |
44.txt | AC | 202 ms | 47872 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 |