#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define ll long long
#define rep(i,n,N) for(int i = n; i<=N; ++i)
#define rap(i,n,N) for(int i = n; i>=N; --i)
#define For(i,n,N) for(int i = n; i< N; ++i)
#define endl '\n'
#define pb push_back
#define all(x) x.begin(),x.end()
#define mems(x,y) memset(x,y,sizeof x)
#define ari(x) array<int,x>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fi first
#define se second
const int MAX = 2500 + 5;
mt19937 rng(99);
int n,m,mnr,mnc,cnt,y[MAX][MAX],z[MAX][MAX];
char c;
bool x[MAX][MAX];
inline bool cek(int r,int c,int dr,int dc){
return y[r][c] - y[r-dr][c] - y[r][c-dc] + y[r-dr][c-dc] == dr*dc;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>m;
mnr = n, mnc = m;
rep(i,1,n){
rep(j,1,m){
cin>>c;
x[i][j] = c=='1';
y[i][j] = y[i-1][j]+y[i][j-1]-y[i-1][j-1]+x[i][j];
if(x[i][j])++cnt;
else if(cnt)mnc = min(mnc, cnt), cnt = 0;
}
if(cnt)mnc = min(mnc, cnt), cnt = 0;
}
rep(j,1,m){
rep(i,1,n){
if(x[i][j])++cnt;
else if(cnt)mnr = min(mnr, cnt), cnt = 0;
}
if(cnt)mnr = min(mnr, cnt), cnt = 0;
}
rep(i,mnr,n)rep(j,mnc,m)if(x[i][j] && cek(i,j,mnr,mnc)){
z[i][j]++;
z[i-mnr][j]--;
z[i][j-mnc]--;
z[i-mnr][j-mnc]++;
}
rap(i,n,1)rap(j,m,1)z[i][j]+= z[i+1][j]+z[i][j+1]-z[i+1][j+1];
rep(i,1,n){
// if(i==1)cout<<"--------------\n";
// rep(j,1,m)cout<<z[i][j];
// cout<<endl;
rep(j,1,m){
if((!!z[i][j])!=x[i][j]){
assert(x[i][j]);
}
}
}
cout<<mnr*mnc<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
11 ms |
26508 KB |
Output is correct |
4 |
Correct |
11 ms |
26452 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
16 |
Correct |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
1364 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
1364 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
1364 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
1236 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
1364 KB |
Output isn't correct |
26 |
Correct |
1 ms |
1364 KB |
Output is correct |
27 |
Correct |
3 ms |
4052 KB |
Output is correct |
28 |
Incorrect |
3 ms |
4180 KB |
Output isn't correct |
29 |
Incorrect |
6 ms |
5332 KB |
Output isn't correct |
30 |
Incorrect |
5 ms |
6228 KB |
Output isn't correct |
31 |
Incorrect |
4 ms |
4948 KB |
Output isn't correct |
32 |
Incorrect |
5 ms |
5716 KB |
Output isn't correct |
33 |
Incorrect |
5 ms |
6612 KB |
Output isn't correct |
34 |
Incorrect |
3 ms |
4692 KB |
Output isn't correct |
35 |
Incorrect |
6 ms |
6612 KB |
Output isn't correct |
36 |
Correct |
6 ms |
6612 KB |
Output is correct |
37 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
38 |
Correct |
103 ms |
55536 KB |
Output is correct |
39 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
40 |
Incorrect |
17 ms |
15408 KB |
Output isn't correct |
41 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
42 |
Incorrect |
1 ms |
1364 KB |
Output isn't correct |
43 |
Correct |
104 ms |
55372 KB |
Output is correct |
44 |
Incorrect |
5 ms |
6612 KB |
Output isn't correct |
45 |
Incorrect |
101 ms |
55468 KB |
Output isn't correct |
46 |
Correct |
112 ms |
55372 KB |
Output is correct |
47 |
Incorrect |
108 ms |
55488 KB |
Output isn't correct |
48 |
Incorrect |
114 ms |
55404 KB |
Output isn't correct |
49 |
Correct |
107 ms |
55388 KB |
Output is correct |
50 |
Incorrect |
104 ms |
55480 KB |
Output isn't correct |
51 |
Incorrect |
105 ms |
55480 KB |
Output isn't correct |
52 |
Incorrect |
105 ms |
55416 KB |
Output isn't correct |
53 |
Incorrect |
106 ms |
55368 KB |
Output isn't correct |
54 |
Incorrect |
107 ms |
55372 KB |
Output isn't correct |
55 |
Incorrect |
107 ms |
55372 KB |
Output isn't correct |
56 |
Correct |
102 ms |
55392 KB |
Output is correct |
57 |
Incorrect |
105 ms |
55372 KB |
Output isn't correct |
58 |
Incorrect |
107 ms |
55372 KB |
Output isn't correct |
59 |
Incorrect |
130 ms |
55380 KB |
Output isn't correct |
60 |
Correct |
104 ms |
55372 KB |
Output is correct |
61 |
Correct |
107 ms |
55372 KB |
Output is correct |
62 |
Correct |
110 ms |
55460 KB |
Output is correct |
63 |
Correct |
100 ms |
55364 KB |
Output is correct |
64 |
Correct |
102 ms |
55432 KB |
Output is correct |
65 |
Incorrect |
104 ms |
55440 KB |
Output isn't correct |
66 |
Incorrect |
120 ms |
55500 KB |
Output isn't correct |
67 |
Incorrect |
106 ms |
55448 KB |
Output isn't correct |
68 |
Incorrect |
106 ms |
55392 KB |
Output isn't correct |
69 |
Incorrect |
108 ms |
55372 KB |
Output isn't correct |
70 |
Incorrect |
73 ms |
44368 KB |
Output isn't correct |
71 |
Incorrect |
103 ms |
55432 KB |
Output isn't correct |
72 |
Incorrect |
102 ms |
55396 KB |
Output isn't correct |
73 |
Incorrect |
102 ms |
55356 KB |
Output isn't correct |
74 |
Incorrect |
104 ms |
55360 KB |
Output isn't correct |
75 |
Incorrect |
102 ms |
55384 KB |
Output isn't correct |
76 |
Incorrect |
105 ms |
55360 KB |
Output isn't correct |
77 |
Incorrect |
109 ms |
55444 KB |
Output isn't correct |
78 |
Incorrect |
102 ms |
55448 KB |
Output isn't correct |
79 |
Incorrect |
103 ms |
55348 KB |
Output isn't correct |
80 |
Incorrect |
103 ms |
55440 KB |
Output isn't correct |
81 |
Incorrect |
105 ms |
55372 KB |
Output isn't correct |
82 |
Incorrect |
111 ms |
55384 KB |
Output isn't correct |
83 |
Incorrect |
105 ms |
55408 KB |
Output isn't correct |
84 |
Incorrect |
103 ms |
55448 KB |
Output isn't correct |
85 |
Incorrect |
103 ms |
55372 KB |
Output isn't correct |
86 |
Incorrect |
105 ms |
55360 KB |
Output isn't correct |
87 |
Incorrect |
107 ms |
55404 KB |
Output isn't correct |
88 |
Incorrect |
102 ms |
55372 KB |
Output isn't correct |
89 |
Incorrect |
105 ms |
55452 KB |
Output isn't correct |
90 |
Incorrect |
74 ms |
44360 KB |
Output isn't correct |
91 |
Incorrect |
101 ms |
55404 KB |
Output isn't correct |
92 |
Incorrect |
104 ms |
55468 KB |
Output isn't correct |
93 |
Incorrect |
116 ms |
55436 KB |
Output isn't correct |
94 |
Incorrect |
108 ms |
55376 KB |
Output isn't correct |
95 |
Incorrect |
110 ms |
55424 KB |
Output isn't correct |
96 |
Incorrect |
104 ms |
55416 KB |
Output isn't correct |
97 |
Incorrect |
112 ms |
55352 KB |
Output isn't correct |
98 |
Incorrect |
105 ms |
55396 KB |
Output isn't correct |
99 |
Incorrect |
104 ms |
55372 KB |
Output isn't correct |
100 |
Incorrect |
105 ms |
55360 KB |
Output isn't correct |