답안 #337916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337916 2020-12-22T05:48:52 Z BY_KUTBILIM Bomb (IZhO17_bomb) C++14
100 / 100
459 ms 55660 KB
/** @BY_KUTBILIM **/
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define all(x) ((x).begin(), (x).end())
#define rall(x) ((x).rbegin(), (x).end())

const int inf = (int)1e9+7;

int up[2505][2505], down[2505][2505];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie();

    int n, m;
    cin >> n >> m;
    bool a[n][m];
    char ch;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> ch;
            a[i][j] = bool(ch - '0');
        }
    }
    int W = m, H = n, len;
    for(int i = 0; i < n; i++){
        len = 0;
        for(int j = 0; j < m; j++){
            if(a[i][j])len++;
            else{
                if(len)W = min(W, len);
                len = 0;
            }
        }
        if(len)W = min(W, len);
    }
    for(int j = 0; j < m; j++){
        len = 0;
        for(int i = 0; i < n; i++){
            if(a[i][j])len++;
            else{
                if(len)H = min(H, len);
                len = 0;
            }
        }
        if(len)H = min(H, len);
    }
    
    for(int j = 0; j < m; j++){
        for(int i = 0; i < n; i++){
            if(a[i][j]){
                up[i][j] = (i ? up[i-1][j] : 0) + 1;
            }
        }
        for(int i = n - 1; i >= 0; i--){
            if(a[i][j]){
                down[i][j] = (i < n - 1 ? down[i+1][j] : 0) + 1;
            }
        }
    }
    
    vector<int> ans(2510, H);
    int l, r;
    for(int i = 0; i < n; i++){
        l = inf, r = inf, len = 0;
        for(int j = 0; j < m; j++){
            if(a[i][j]){
                r = min(r, up[i][j]);
                l = min(l, down[i][j]);
                ans[len] = min(ans[len], r + l - 1);
                len++;
            } else len = 0, l = inf, r = inf;
        }
        l = inf, r = inf, len = 0;
        for(int j = m - 1; j >= 0; j--){
            if(a[i][j]){
                r = min(r, up[i][j]);
                l = min(l, down[i][j]);
                ans[len] = min(ans[len], r + l - 1);
                len++;
            } else len = 0, l = inf, r = inf;
        }
    }
    int res = ans[0];
    for(int i = 1; i < W; i++){
        ans[i] = min(ans[i], ans[i-1]);
        res = max(res, ans[i] * (i+1));
    }
    cout << res;
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 17 ms 20460 KB Output is correct
4 Correct 12 ms 20332 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
18 Correct 1 ms 620 KB Output is correct
19 Correct 1 ms 876 KB Output is correct
20 Correct 1 ms 876 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 620 KB Output is correct
23 Correct 1 ms 876 KB Output is correct
24 Correct 1 ms 876 KB Output is correct
25 Correct 1 ms 1132 KB Output is correct
26 Correct 2 ms 1280 KB Output is correct
27 Correct 5 ms 3436 KB Output is correct
28 Correct 4 ms 876 KB Output is correct
29 Correct 7 ms 4332 KB Output is correct
30 Correct 7 ms 3308 KB Output is correct
31 Correct 6 ms 2412 KB Output is correct
32 Correct 6 ms 3180 KB Output is correct
33 Correct 9 ms 4332 KB Output is correct
34 Correct 4 ms 1004 KB Output is correct
35 Correct 7 ms 1132 KB Output is correct
36 Correct 12 ms 5772 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 436 ms 55532 KB Output is correct
39 Correct 1 ms 492 KB Output is correct
40 Correct 50 ms 14216 KB Output is correct
41 Correct 1 ms 492 KB Output is correct
42 Correct 1 ms 1132 KB Output is correct
43 Correct 395 ms 51564 KB Output is correct
44 Correct 9 ms 5120 KB Output is correct
45 Correct 395 ms 52972 KB Output is correct
46 Correct 385 ms 55532 KB Output is correct
47 Correct 409 ms 53008 KB Output is correct
48 Correct 364 ms 55532 KB Output is correct
49 Correct 450 ms 55532 KB Output is correct
50 Correct 386 ms 55532 KB Output is correct
51 Correct 366 ms 55516 KB Output is correct
52 Correct 382 ms 55404 KB Output is correct
53 Correct 373 ms 54764 KB Output is correct
54 Correct 325 ms 42252 KB Output is correct
55 Correct 313 ms 40428 KB Output is correct
56 Correct 449 ms 55660 KB Output is correct
57 Correct 316 ms 35484 KB Output is correct
58 Correct 316 ms 40556 KB Output is correct
59 Correct 300 ms 37356 KB Output is correct
60 Correct 365 ms 47320 KB Output is correct
61 Correct 449 ms 55532 KB Output is correct
62 Correct 456 ms 55532 KB Output is correct
63 Correct 459 ms 55532 KB Output is correct
64 Correct 322 ms 38380 KB Output is correct
65 Correct 364 ms 54380 KB Output is correct
66 Correct 382 ms 51308 KB Output is correct
67 Correct 387 ms 55532 KB Output is correct
68 Correct 387 ms 55480 KB Output is correct
69 Correct 308 ms 35052 KB Output is correct
70 Correct 143 ms 14316 KB Output is correct
71 Correct 273 ms 28268 KB Output is correct
72 Correct 304 ms 33644 KB Output is correct
73 Correct 308 ms 34028 KB Output is correct
74 Correct 312 ms 35564 KB Output is correct
75 Correct 308 ms 37184 KB Output is correct
76 Correct 311 ms 38636 KB Output is correct
77 Correct 310 ms 39188 KB Output is correct
78 Correct 330 ms 39364 KB Output is correct
79 Correct 248 ms 11676 KB Output is correct
80 Correct 235 ms 13108 KB Output is correct
81 Correct 251 ms 13420 KB Output is correct
82 Correct 324 ms 41836 KB Output is correct
83 Correct 322 ms 42072 KB Output is correct
84 Correct 237 ms 7036 KB Output is correct
85 Correct 306 ms 40812 KB Output is correct
86 Correct 427 ms 54324 KB Output is correct
87 Correct 312 ms 39832 KB Output is correct
88 Correct 317 ms 40940 KB Output is correct
89 Correct 347 ms 49424 KB Output is correct
90 Correct 171 ms 28448 KB Output is correct
91 Correct 352 ms 44652 KB Output is correct
92 Correct 360 ms 46316 KB Output is correct
93 Correct 419 ms 53632 KB Output is correct
94 Correct 356 ms 48108 KB Output is correct
95 Correct 314 ms 41964 KB Output is correct
96 Correct 312 ms 41836 KB Output is correct
97 Correct 448 ms 54508 KB Output is correct
98 Correct 320 ms 41452 KB Output is correct
99 Correct 365 ms 47724 KB Output is correct
100 Correct 417 ms 53104 KB Output is correct