답안 #93830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93830 2019-01-11T23:48:39 Z dalgerok Bomb (IZhO17_bomb) C++14
100 / 100
465 ms 61688 KB
#include<bits/stdc++.h>
using namespace std;



const int N = 2505, INF = 2e9;



int n, m, dn[N][N], up[N][N];
char a[N][N];
int dp[N];


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> a[i][j];
        }
    }
    int mnw = INF, mnh = INF;
    for(int i = 1; i <= n; i++){
        int cur = 0;
        for(int j = 1; j <= m; j++){
            if(a[i][j] == '1'){
                cur += 1;
            }
            else if(cur > 0){
                mnw = min(mnw, cur);
                cur = 0;
            }
        }
        if(cur > 0){
            mnw = min(mnw, cur);
        }
    }
    for(int j = 1; j <= m; j++){
        int cur = 0;
        for(int i = 1; i <= n; i++){
            if(a[i][j] == '1'){
                cur += 1;
            }
            else if(cur > 0){
                mnh = min(mnh, cur);
                cur = 0;
            }
        }
        if(cur > 0){
            mnh = min(mnh, cur);
        }
    }
    for(int j = 1; j <= m; j++){
        for(int i = 1; i <= n; i++){
            if(a[i][j] == '1'){
                up[i][j] = up[i - 1][j] + 1;
            }
        }
        for(int i = n; i >= 1; i--){
            if(a[i][j] == '1'){
                dn[i][j] = dn[i + 1][j] + 1;
            }
        }
    }
    for(int i = 1; i <= mnw; i++){
        dp[i] = mnh;
    }
    for(int i = 1; i <= n; i++){
        int l = INF, r = INF, cur = 0;
        for(int j = 1; j <= m; j++){
            if(a[i][j] == '1'){
                l = min(l, up[i][j]);
                r = min(r, dn[i][j]);
                cur += 1;
                dp[cur] = min(dp[cur], l + r - 1);
            }
            else{
                l = r = INF;
                cur = 0;
            }
        }
        l = r = INF;
        cur = 0;
        for(int j = m; j >= 1; j--){
            if(a[i][j] == '1'){
                l = min(l, up[i][j]);
                r = min(r, dn[i][j]);
                cur += 1;
                dp[cur] = min(dp[cur], l + r - 1);
            }
            else{
                l = r = INF;
                cur = 0;
            }
        }
    }
    int ans = dp[1];
    for(int i = 2; i <= mnw; i++){
        dp[i] = min(dp[i], dp[i - 1]);
        ans = max(ans, dp[i] * i);
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 18 ms 26516 KB Output is correct
4 Correct 17 ms 26488 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 508 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 3 ms 1016 KB Output is correct
18 Correct 2 ms 888 KB Output is correct
19 Correct 2 ms 1016 KB Output is correct
20 Correct 2 ms 1016 KB Output is correct
21 Correct 2 ms 632 KB Output is correct
22 Correct 2 ms 888 KB Output is correct
23 Correct 2 ms 1144 KB Output is correct
24 Correct 2 ms 1016 KB Output is correct
25 Correct 2 ms 1400 KB Output is correct
26 Correct 3 ms 1528 KB Output is correct
27 Correct 6 ms 4088 KB Output is correct
28 Correct 4 ms 1528 KB Output is correct
29 Correct 8 ms 5240 KB Output is correct
30 Correct 7 ms 4324 KB Output is correct
31 Correct 6 ms 3064 KB Output is correct
32 Correct 7 ms 4216 KB Output is correct
33 Correct 9 ms 5368 KB Output is correct
34 Correct 4 ms 1768 KB Output is correct
35 Correct 6 ms 2168 KB Output is correct
36 Correct 11 ms 6776 KB Output is correct
37 Correct 2 ms 632 KB Output is correct
38 Correct 465 ms 61432 KB Output is correct
39 Correct 2 ms 632 KB Output is correct
40 Correct 36 ms 16160 KB Output is correct
41 Correct 2 ms 632 KB Output is correct
42 Correct 2 ms 1528 KB Output is correct
43 Correct 289 ms 57592 KB Output is correct
44 Correct 9 ms 6136 KB Output is correct
45 Correct 273 ms 59000 KB Output is correct
46 Correct 270 ms 61432 KB Output is correct
47 Correct 277 ms 59000 KB Output is correct
48 Correct 264 ms 61532 KB Output is correct
49 Correct 349 ms 61432 KB Output is correct
50 Correct 374 ms 61688 KB Output is correct
51 Correct 265 ms 61432 KB Output is correct
52 Correct 274 ms 61432 KB Output is correct
53 Correct 263 ms 60808 KB Output is correct
54 Correct 208 ms 48248 KB Output is correct
55 Correct 219 ms 46456 KB Output is correct
56 Correct 354 ms 61532 KB Output is correct
57 Correct 200 ms 41444 KB Output is correct
58 Correct 228 ms 46560 KB Output is correct
59 Correct 209 ms 43504 KB Output is correct
60 Correct 274 ms 53240 KB Output is correct
61 Correct 370 ms 61432 KB Output is correct
62 Correct 377 ms 61432 KB Output is correct
63 Correct 387 ms 61560 KB Output is correct
64 Correct 201 ms 44280 KB Output is correct
65 Correct 290 ms 60404 KB Output is correct
66 Correct 283 ms 57316 KB Output is correct
67 Correct 291 ms 61484 KB Output is correct
68 Correct 339 ms 61560 KB Output is correct
69 Correct 219 ms 41080 KB Output is correct
70 Correct 103 ms 19064 KB Output is correct
71 Correct 166 ms 34168 KB Output is correct
72 Correct 187 ms 39672 KB Output is correct
73 Correct 202 ms 40184 KB Output is correct
74 Correct 202 ms 41592 KB Output is correct
75 Correct 201 ms 43228 KB Output is correct
76 Correct 203 ms 44508 KB Output is correct
77 Correct 207 ms 45080 KB Output is correct
78 Correct 226 ms 45304 KB Output is correct
79 Correct 133 ms 17784 KB Output is correct
80 Correct 133 ms 19064 KB Output is correct
81 Correct 156 ms 19396 KB Output is correct
82 Correct 229 ms 47820 KB Output is correct
83 Correct 214 ms 47868 KB Output is correct
84 Correct 120 ms 13048 KB Output is correct
85 Correct 220 ms 46980 KB Output is correct
86 Correct 339 ms 60524 KB Output is correct
87 Correct 204 ms 45784 KB Output is correct
88 Correct 215 ms 46908 KB Output is correct
89 Correct 252 ms 55416 KB Output is correct
90 Correct 116 ms 33272 KB Output is correct
91 Correct 220 ms 50540 KB Output is correct
92 Correct 260 ms 52172 KB Output is correct
93 Correct 332 ms 59476 KB Output is correct
94 Correct 252 ms 54140 KB Output is correct
95 Correct 210 ms 47992 KB Output is correct
96 Correct 227 ms 47736 KB Output is correct
97 Correct 330 ms 60320 KB Output is correct
98 Correct 209 ms 47480 KB Output is correct
99 Correct 270 ms 53752 KB Output is correct
100 Correct 336 ms 59128 KB Output is correct