# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
91424 |
2018-12-27T12:35:17 Z |
Vardanyan |
Bomb (IZhO17_bomb) |
C++14 |
|
1000 ms |
74364 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 2505;
int a[N][N];
int pref[N][N];
int pref2[N][N];
int calc1(int x1,int y1,int x2,int y2){
return pref[x2][y2]-pref[x2][y1-1]-pref[x1-1][y2]+pref[x1-1][y1-1];
}
int calc2(int x1,int y1,int x2,int y2){
return pref2[x2][y2]-pref2[x2][y1-1]-pref2[x1-1][y2]+pref2[x1-1][y1-1];
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
char c;
scanf(" %c",&c);
a[i][j] = (c == '1');
}
}
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
pref[i][j] = pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1]+a[i][j];
}
}
int ans = 1;
for(int p = n;p>=1;p--){
int lo = 1;
int hi = m;
int as = -1;
while(lo<=hi){
int mid = (lo+hi)/2;
int x = p;
int y = mid;
bool f = true;
for(int i = 1;i<=n;i++)
for(int j = 1;j<=m;j++) pref2[i][j] = 0;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
// if(a[i][j]!=1) continue;
pref2[i][j] = pref2[i-1][j]+pref2[i][j-1]-pref2[i-1][j-1];
if(i+x-1<=n && j+y-1<=m){
if(calc1(i,j,i+x-1,j+y-1) == mid*p){
pref2[i][j] = pref2[i-1][j]+pref2[i][j-1]-pref2[i-1][j-1]+1;
}
}
if(a[i][j] == 0) continue;
int x1 = i-x+1;
int y1 = j-y+1;
x1 = max(1,x1);
y1 = max(1,y1);
if(calc2(x1,y1,i,j) == 0){
f = false;
break;
}
}
}
if(f){
// F = true;
// break;
lo = mid+1;
as = mid;
continue;
}
swap(x,y);
f = true;
for(int i = 1;i<=n;i++)
for(int j = 1;j<=m;j++) pref2[i][j] = 0;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
// if(a[i][j]!=1) continue;
pref2[i][j] = pref2[i-1][j]+pref2[i][j-1]-pref2[i-1][j-1];
if(i+x-1<=n && j+y-1<=m){
if(calc1(i,j,i+x-1,j+y-1) == mid*p){
pref2[i][j] = pref2[i-1][j]+pref2[i][j-1]-pref2[i-1][j-1]+1;
}
}
if(a[i][j] == 0) continue;
int x1 = i-x+1;
int y1 = j-y+1;
x1 = max(1,x1);
y1 = max(1,y1);
if(calc2(x1,y1,i,j) == 0){
f = false;
break;
}
}
}
if(f){
// F = true;
// break;
lo = mid+1;
as = mid;
continue;
}
hi = mid-1;
}
if(as == -1) continue;
ans = max(ans,as*p);
}
cout<<ans<<endl;
return 0;
}
Compilation message
bomb.cpp: In function 'int main()':
bomb.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
bomb.cpp:21:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c",&c);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
720 KB |
Output is correct |
3 |
Correct |
496 ms |
30576 KB |
Output is correct |
4 |
Correct |
507 ms |
30624 KB |
Output is correct |
5 |
Correct |
2 ms |
30624 KB |
Output is correct |
6 |
Correct |
2 ms |
30624 KB |
Output is correct |
7 |
Correct |
2 ms |
30624 KB |
Output is correct |
8 |
Correct |
2 ms |
30624 KB |
Output is correct |
9 |
Correct |
2 ms |
30624 KB |
Output is correct |
10 |
Correct |
2 ms |
30624 KB |
Output is correct |
11 |
Correct |
2 ms |
30624 KB |
Output is correct |
12 |
Correct |
2 ms |
30624 KB |
Output is correct |
13 |
Correct |
2 ms |
30624 KB |
Output is correct |
14 |
Correct |
2 ms |
30624 KB |
Output is correct |
15 |
Correct |
2 ms |
30624 KB |
Output is correct |
16 |
Correct |
2 ms |
30624 KB |
Output is correct |
17 |
Correct |
6 ms |
30624 KB |
Output is correct |
18 |
Correct |
9 ms |
30624 KB |
Output is correct |
19 |
Correct |
21 ms |
30624 KB |
Output is correct |
20 |
Correct |
22 ms |
30624 KB |
Output is correct |
21 |
Correct |
10 ms |
30624 KB |
Output is correct |
22 |
Correct |
16 ms |
30624 KB |
Output is correct |
23 |
Correct |
34 ms |
30624 KB |
Output is correct |
24 |
Correct |
15 ms |
30624 KB |
Output is correct |
25 |
Correct |
33 ms |
30624 KB |
Output is correct |
26 |
Correct |
40 ms |
30624 KB |
Output is correct |
27 |
Correct |
418 ms |
30624 KB |
Output is correct |
28 |
Execution timed out |
1086 ms |
30624 KB |
Time limit exceeded |
29 |
Execution timed out |
1071 ms |
30624 KB |
Time limit exceeded |
30 |
Execution timed out |
1075 ms |
30624 KB |
Time limit exceeded |
31 |
Execution timed out |
1081 ms |
30624 KB |
Time limit exceeded |
32 |
Execution timed out |
1077 ms |
30624 KB |
Time limit exceeded |
33 |
Execution timed out |
1088 ms |
30624 KB |
Time limit exceeded |
34 |
Execution timed out |
1089 ms |
30624 KB |
Time limit exceeded |
35 |
Execution timed out |
1073 ms |
30624 KB |
Time limit exceeded |
36 |
Execution timed out |
1072 ms |
30624 KB |
Time limit exceeded |
37 |
Correct |
2 ms |
30624 KB |
Output is correct |
38 |
Execution timed out |
1094 ms |
74080 KB |
Time limit exceeded |
39 |
Correct |
2 ms |
74080 KB |
Output is correct |
40 |
Execution timed out |
1071 ms |
74080 KB |
Time limit exceeded |
41 |
Correct |
2 ms |
74080 KB |
Output is correct |
42 |
Correct |
31 ms |
74080 KB |
Output is correct |
43 |
Execution timed out |
1094 ms |
74080 KB |
Time limit exceeded |
44 |
Execution timed out |
1089 ms |
74080 KB |
Time limit exceeded |
45 |
Execution timed out |
1092 ms |
74104 KB |
Time limit exceeded |
46 |
Execution timed out |
1088 ms |
74104 KB |
Time limit exceeded |
47 |
Execution timed out |
1084 ms |
74216 KB |
Time limit exceeded |
48 |
Execution timed out |
1075 ms |
74216 KB |
Time limit exceeded |
49 |
Execution timed out |
1081 ms |
74216 KB |
Time limit exceeded |
50 |
Execution timed out |
1091 ms |
74220 KB |
Time limit exceeded |
51 |
Execution timed out |
1085 ms |
74236 KB |
Time limit exceeded |
52 |
Execution timed out |
1082 ms |
74236 KB |
Time limit exceeded |
53 |
Execution timed out |
1088 ms |
74236 KB |
Time limit exceeded |
54 |
Execution timed out |
1080 ms |
74236 KB |
Time limit exceeded |
55 |
Execution timed out |
1083 ms |
74236 KB |
Time limit exceeded |
56 |
Execution timed out |
1089 ms |
74236 KB |
Time limit exceeded |
57 |
Execution timed out |
1067 ms |
74236 KB |
Time limit exceeded |
58 |
Execution timed out |
1082 ms |
74260 KB |
Time limit exceeded |
59 |
Execution timed out |
1084 ms |
74260 KB |
Time limit exceeded |
60 |
Execution timed out |
1086 ms |
74260 KB |
Time limit exceeded |
61 |
Execution timed out |
1078 ms |
74260 KB |
Time limit exceeded |
62 |
Execution timed out |
1094 ms |
74260 KB |
Time limit exceeded |
63 |
Execution timed out |
1070 ms |
74304 KB |
Time limit exceeded |
64 |
Execution timed out |
1076 ms |
74304 KB |
Time limit exceeded |
65 |
Execution timed out |
1070 ms |
74304 KB |
Time limit exceeded |
66 |
Execution timed out |
1090 ms |
74304 KB |
Time limit exceeded |
67 |
Execution timed out |
1094 ms |
74304 KB |
Time limit exceeded |
68 |
Execution timed out |
1082 ms |
74304 KB |
Time limit exceeded |
69 |
Execution timed out |
1087 ms |
74304 KB |
Time limit exceeded |
70 |
Execution timed out |
1078 ms |
74304 KB |
Time limit exceeded |
71 |
Execution timed out |
1091 ms |
74304 KB |
Time limit exceeded |
72 |
Execution timed out |
1084 ms |
74304 KB |
Time limit exceeded |
73 |
Execution timed out |
1083 ms |
74304 KB |
Time limit exceeded |
74 |
Execution timed out |
1091 ms |
74304 KB |
Time limit exceeded |
75 |
Execution timed out |
1085 ms |
74304 KB |
Time limit exceeded |
76 |
Execution timed out |
1075 ms |
74304 KB |
Time limit exceeded |
77 |
Execution timed out |
1075 ms |
74304 KB |
Time limit exceeded |
78 |
Execution timed out |
1084 ms |
74304 KB |
Time limit exceeded |
79 |
Execution timed out |
1080 ms |
74304 KB |
Time limit exceeded |
80 |
Execution timed out |
1084 ms |
74304 KB |
Time limit exceeded |
81 |
Execution timed out |
1085 ms |
74304 KB |
Time limit exceeded |
82 |
Execution timed out |
1083 ms |
74304 KB |
Time limit exceeded |
83 |
Execution timed out |
1083 ms |
74304 KB |
Time limit exceeded |
84 |
Execution timed out |
1098 ms |
74304 KB |
Time limit exceeded |
85 |
Execution timed out |
1092 ms |
74304 KB |
Time limit exceeded |
86 |
Execution timed out |
1082 ms |
74304 KB |
Time limit exceeded |
87 |
Execution timed out |
1092 ms |
74304 KB |
Time limit exceeded |
88 |
Execution timed out |
1081 ms |
74304 KB |
Time limit exceeded |
89 |
Execution timed out |
1082 ms |
74304 KB |
Time limit exceeded |
90 |
Execution timed out |
1084 ms |
74304 KB |
Time limit exceeded |
91 |
Execution timed out |
1084 ms |
74304 KB |
Time limit exceeded |
92 |
Execution timed out |
1083 ms |
74364 KB |
Time limit exceeded |
93 |
Execution timed out |
1083 ms |
74364 KB |
Time limit exceeded |
94 |
Execution timed out |
1092 ms |
74364 KB |
Time limit exceeded |
95 |
Execution timed out |
1082 ms |
74364 KB |
Time limit exceeded |
96 |
Execution timed out |
1087 ms |
74364 KB |
Time limit exceeded |
97 |
Execution timed out |
1056 ms |
74364 KB |
Time limit exceeded |
98 |
Execution timed out |
1079 ms |
74364 KB |
Time limit exceeded |
99 |
Execution timed out |
1077 ms |
74364 KB |
Time limit exceeded |
100 |
Execution timed out |
1083 ms |
74364 KB |
Time limit exceeded |