#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<=n;j++){
pref[i][j] = pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1]+a[i][j];
}
}
int l = 1;
int r = n*m;
int ans = 1;
while(l<=r){
int mid = (l+r)/2;
bool F = false;
for(int q = 1;q<=sqrt(mid);q++){
if(mid%q) continue;
int x = mid/q;
int y = q;
bool f = true;
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){
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;
}
swap(x,y);
f = true;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
if(a[i][j]!=1) continue;
if(i+x-1<=n && j+y-1<=m){
if(calc1(i,j,i+x-1,j+y-1) == mid){
pref2[i][j] = pref2[i-1][j]+pref2[i][j-1]-pref2[i-1][j-1]+1;
}
else{
pref2[i][j] = pref2[i-1][j]+pref2[i][j-1]-pref2[i-1][j-1];
}
}
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){
ans = mid;
l = mid+1;
}
else r = mid-1;
}
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);
~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
60 ms |
45160 KB |
Output is correct |
4 |
Correct |
62 ms |
45276 KB |
Output is correct |
5 |
Incorrect |
2 ms |
45276 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
45276 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
45276 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
45276 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
45276 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
45276 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
45276 KB |
Output isn't correct |
12 |
Correct |
2 ms |
45276 KB |
Output is correct |
13 |
Incorrect |
2 ms |
45276 KB |
Output isn't correct |
14 |
Correct |
2 ms |
45276 KB |
Output is correct |
15 |
Incorrect |
2 ms |
45276 KB |
Output isn't correct |
16 |
Incorrect |
2 ms |
45276 KB |
Output isn't correct |
17 |
Incorrect |
3 ms |
45276 KB |
Output isn't correct |
18 |
Correct |
3 ms |
45276 KB |
Output is correct |
19 |
Incorrect |
4 ms |
45276 KB |
Output isn't correct |
20 |
Incorrect |
4 ms |
45276 KB |
Output isn't correct |
21 |
Correct |
3 ms |
45276 KB |
Output is correct |
22 |
Incorrect |
4 ms |
45276 KB |
Output isn't correct |
23 |
Incorrect |
5 ms |
45276 KB |
Output isn't correct |
24 |
Incorrect |
3 ms |
45276 KB |
Output isn't correct |
25 |
Incorrect |
5 ms |
45276 KB |
Output isn't correct |
26 |
Incorrect |
5 ms |
45276 KB |
Output isn't correct |
27 |
Incorrect |
20 ms |
45276 KB |
Output isn't correct |
28 |
Incorrect |
27 ms |
45276 KB |
Output isn't correct |
29 |
Incorrect |
75 ms |
45276 KB |
Output isn't correct |
30 |
Incorrect |
84 ms |
45276 KB |
Output isn't correct |
31 |
Incorrect |
36 ms |
45276 KB |
Output isn't correct |
32 |
Incorrect |
34 ms |
45276 KB |
Output isn't correct |
33 |
Incorrect |
62 ms |
45276 KB |
Output isn't correct |
34 |
Correct |
30 ms |
45276 KB |
Output is correct |
35 |
Incorrect |
84 ms |
45276 KB |
Output isn't correct |
36 |
Incorrect |
56 ms |
45276 KB |
Output isn't correct |
37 |
Incorrect |
2 ms |
45276 KB |
Output isn't correct |
38 |
Incorrect |
469 ms |
82076 KB |
Output isn't correct |
39 |
Incorrect |
2 ms |
82076 KB |
Output isn't correct |
40 |
Incorrect |
191 ms |
82076 KB |
Output isn't correct |
41 |
Incorrect |
2 ms |
82076 KB |
Output isn't correct |
42 |
Incorrect |
5 ms |
82076 KB |
Output isn't correct |
43 |
Execution timed out |
1073 ms |
89024 KB |
Time limit exceeded |
44 |
Incorrect |
61 ms |
89024 KB |
Output isn't correct |
45 |
Execution timed out |
1093 ms |
95288 KB |
Time limit exceeded |
46 |
Incorrect |
531 ms |
101416 KB |
Output isn't correct |
47 |
Execution timed out |
1086 ms |
107672 KB |
Time limit exceeded |
48 |
Execution timed out |
1085 ms |
107896 KB |
Time limit exceeded |
49 |
Execution timed out |
1085 ms |
119968 KB |
Time limit exceeded |
50 |
Execution timed out |
1080 ms |
125820 KB |
Time limit exceeded |
51 |
Execution timed out |
1091 ms |
125820 KB |
Time limit exceeded |
52 |
Execution timed out |
1076 ms |
132096 KB |
Time limit exceeded |
53 |
Execution timed out |
1089 ms |
132096 KB |
Time limit exceeded |
54 |
Execution timed out |
1085 ms |
132096 KB |
Time limit exceeded |
55 |
Execution timed out |
1093 ms |
132096 KB |
Time limit exceeded |
56 |
Runtime error |
536 ms |
132096 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
57 |
Execution timed out |
1089 ms |
132096 KB |
Time limit exceeded |
58 |
Execution timed out |
1090 ms |
132096 KB |
Time limit exceeded |
59 |
Execution timed out |
1085 ms |
132096 KB |
Time limit exceeded |
60 |
Execution timed out |
1093 ms |
132096 KB |
Time limit exceeded |
61 |
Execution timed out |
1084 ms |
132096 KB |
Time limit exceeded |
62 |
Execution timed out |
1094 ms |
132096 KB |
Time limit exceeded |
63 |
Runtime error |
889 ms |
132096 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
64 |
Execution timed out |
1075 ms |
132096 KB |
Time limit exceeded |
65 |
Execution timed out |
1095 ms |
132096 KB |
Time limit exceeded |
66 |
Execution timed out |
1095 ms |
132096 KB |
Time limit exceeded |
67 |
Execution timed out |
1076 ms |
132096 KB |
Time limit exceeded |
68 |
Execution timed out |
1084 ms |
132096 KB |
Time limit exceeded |
69 |
Execution timed out |
1085 ms |
132096 KB |
Time limit exceeded |
70 |
Execution timed out |
1064 ms |
132096 KB |
Time limit exceeded |
71 |
Execution timed out |
1094 ms |
132096 KB |
Time limit exceeded |
72 |
Execution timed out |
1091 ms |
132096 KB |
Time limit exceeded |
73 |
Execution timed out |
1093 ms |
132096 KB |
Time limit exceeded |
74 |
Execution timed out |
1086 ms |
132096 KB |
Time limit exceeded |
75 |
Execution timed out |
1088 ms |
132096 KB |
Time limit exceeded |
76 |
Execution timed out |
1083 ms |
132096 KB |
Time limit exceeded |
77 |
Execution timed out |
1089 ms |
132096 KB |
Time limit exceeded |
78 |
Execution timed out |
1095 ms |
132096 KB |
Time limit exceeded |
79 |
Execution timed out |
1098 ms |
132096 KB |
Time limit exceeded |
80 |
Execution timed out |
1086 ms |
132096 KB |
Time limit exceeded |
81 |
Execution timed out |
1085 ms |
132096 KB |
Time limit exceeded |
82 |
Execution timed out |
1073 ms |
132096 KB |
Time limit exceeded |
83 |
Execution timed out |
1084 ms |
132096 KB |
Time limit exceeded |
84 |
Execution timed out |
1082 ms |
132096 KB |
Time limit exceeded |
85 |
Execution timed out |
1091 ms |
132096 KB |
Time limit exceeded |
86 |
Execution timed out |
1091 ms |
132096 KB |
Time limit exceeded |
87 |
Execution timed out |
1070 ms |
132096 KB |
Time limit exceeded |
88 |
Execution timed out |
1093 ms |
132096 KB |
Time limit exceeded |
89 |
Execution timed out |
1086 ms |
132096 KB |
Time limit exceeded |
90 |
Execution timed out |
1079 ms |
132096 KB |
Time limit exceeded |
91 |
Execution timed out |
1075 ms |
132096 KB |
Time limit exceeded |
92 |
Execution timed out |
1078 ms |
132096 KB |
Time limit exceeded |
93 |
Execution timed out |
1085 ms |
132096 KB |
Time limit exceeded |
94 |
Execution timed out |
1085 ms |
132096 KB |
Time limit exceeded |
95 |
Execution timed out |
1088 ms |
132096 KB |
Time limit exceeded |
96 |
Execution timed out |
1078 ms |
132096 KB |
Time limit exceeded |
97 |
Execution timed out |
1090 ms |
132096 KB |
Time limit exceeded |
98 |
Execution timed out |
1073 ms |
132096 KB |
Time limit exceeded |
99 |
Execution timed out |
1078 ms |
132096 KB |
Time limit exceeded |
100 |
Execution timed out |
1081 ms |
132096 KB |
Time limit exceeded |