Submission #96804

# Submission time Handle Problem Language Result Execution time Memory
96804 2019-02-12T04:19:27 Z choikiwon Bomb (IZhO17_bomb) C++17
100 / 100
854 ms 112472 KB
#include<bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;

const int MN = 2525;

int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

int N, M;
char G[MN][MN];

int cc[MN][MN][4];
int dp(int r, int c, int d) {
    if(r < 0 || N <= r || c < 0 || M <= c) return 0;
    int &ret = cc[r][c][d];
    if(ret != -1) return ret;
    if(G[r][c] == '0') return ret = 0;
    return ret = dp(r + dy[d], c + dx[d], d) + 1;
}

int mn[MN];

int main() {
    //freopen("input.txt", "r", stdin);

    scanf("%d %d", &N, &M);

    for(int i = 0; i < N; i++) {
        scanf("\n");
        for(int j = 0; j < M; j++) {
            scanf("%c", &G[i][j]);
        }
    }
    //*/
    memset(cc, -1, sizeof(cc));

    int mnh = 1e9;
    int mnw = 1e9;
    for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) if(G[i][j] == '1') {
        mnh = min(mnh, dp(i, j, 0) + dp(i, j, 1) - 1);
        mnw = min(mnw, dp(i, j, 2) + dp(i, j, 3) - 1);
    }

    for(int i = 0; i <= mnw; i++) mn[i] = 1e9;
    mn[0] = mnh;
    for(int i = 0; i < N; i++) {
        int len = 0;
        int x = 1e9, y = 1e9;
        for(int j = 0; j < M; j++) {
            if(G[i][j] == '1') {
                if(dp(i, j, 3) == 1) {
                    len = 1;
                }
                if(len) {
                    x = min(x, dp(i, j, 0));
                    y = min(y, dp(i, j, 1));
                    mn[len] = min(mn[len], x + y - 1);
                }
                len++;
            }
            else len = 0, x = y = 1e9;
        }
        len = 0;
        x = y = 1e9;
        for(int j = M - 1; j >= 0; j--) {
            if(G[i][j] == '1') {
                if(dp(i, j, 2) == 1) {
                    len = 1;
                }
                if(len) {
                    x = min(x, dp(i, j, 0));
                    y = min(y, dp(i, j, 1));
                    mn[len] = min(mn[len], x + y - 1);
                }
                len++;
            }
            else len = 0, x = y = 1e9;
        }
    }
    int ans = 0;
    for(int i = 1; i <= mnw; i++) {
        mn[i] = min(mn[i], mn[i - 1]);
        ans = max(ans, mn[i] * i);
    }
    printf("%d", ans);
}

Compilation message

bomb.cpp: In function 'int main()':
bomb.cpp:28: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:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("\n");
         ~~~~~^~~~~~
bomb.cpp:33:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%c", &G[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 69 ms 100088 KB Output is correct
2 Correct 87 ms 100216 KB Output is correct
3 Correct 86 ms 106360 KB Output is correct
4 Correct 84 ms 106356 KB Output is correct
5 Correct 79 ms 100088 KB Output is correct
6 Correct 77 ms 100176 KB Output is correct
7 Correct 76 ms 100080 KB Output is correct
8 Correct 79 ms 100220 KB Output is correct
9 Correct 88 ms 100184 KB Output is correct
10 Correct 79 ms 100132 KB Output is correct
11 Correct 78 ms 100192 KB Output is correct
12 Correct 80 ms 100188 KB Output is correct
13 Correct 80 ms 100144 KB Output is correct
14 Correct 82 ms 100156 KB Output is correct
15 Correct 79 ms 100212 KB Output is correct
16 Correct 87 ms 100208 KB Output is correct
17 Correct 78 ms 100344 KB Output is correct
18 Correct 79 ms 100348 KB Output is correct
19 Correct 82 ms 100416 KB Output is correct
20 Correct 86 ms 100384 KB Output is correct
21 Correct 81 ms 100288 KB Output is correct
22 Correct 80 ms 100348 KB Output is correct
23 Correct 81 ms 100332 KB Output is correct
24 Correct 78 ms 100412 KB Output is correct
25 Correct 80 ms 100400 KB Output is correct
26 Correct 81 ms 100392 KB Output is correct
27 Correct 88 ms 100828 KB Output is correct
28 Correct 100 ms 100956 KB Output is correct
29 Correct 94 ms 101176 KB Output is correct
30 Correct 88 ms 101196 KB Output is correct
31 Correct 87 ms 100948 KB Output is correct
32 Correct 91 ms 101112 KB Output is correct
33 Correct 89 ms 101216 KB Output is correct
34 Correct 82 ms 100996 KB Output is correct
35 Correct 89 ms 101312 KB Output is correct
36 Correct 98 ms 101324 KB Output is correct
37 Correct 79 ms 100216 KB Output is correct
38 Correct 819 ms 112208 KB Output is correct
39 Correct 68 ms 100344 KB Output is correct
40 Correct 155 ms 102780 KB Output is correct
41 Correct 80 ms 100216 KB Output is correct
42 Correct 98 ms 100344 KB Output is correct
43 Correct 688 ms 112120 KB Output is correct
44 Correct 99 ms 101244 KB Output is correct
45 Correct 603 ms 112328 KB Output is correct
46 Correct 535 ms 112248 KB Output is correct
47 Correct 601 ms 112248 KB Output is correct
48 Correct 556 ms 112428 KB Output is correct
49 Correct 854 ms 112412 KB Output is correct
50 Correct 591 ms 112264 KB Output is correct
51 Correct 565 ms 112248 KB Output is correct
52 Correct 545 ms 112248 KB Output is correct
53 Correct 528 ms 112296 KB Output is correct
54 Correct 424 ms 112124 KB Output is correct
55 Correct 449 ms 112252 KB Output is correct
56 Correct 818 ms 112120 KB Output is correct
57 Correct 437 ms 112120 KB Output is correct
58 Correct 426 ms 112192 KB Output is correct
59 Correct 415 ms 112120 KB Output is correct
60 Correct 562 ms 112288 KB Output is correct
61 Correct 793 ms 112248 KB Output is correct
62 Correct 731 ms 112248 KB Output is correct
63 Correct 772 ms 112216 KB Output is correct
64 Correct 437 ms 112248 KB Output is correct
65 Correct 548 ms 112120 KB Output is correct
66 Correct 509 ms 112292 KB Output is correct
67 Correct 586 ms 112472 KB Output is correct
68 Correct 635 ms 112376 KB Output is correct
69 Correct 416 ms 112220 KB Output is correct
70 Correct 261 ms 108780 KB Output is correct
71 Correct 367 ms 112220 KB Output is correct
72 Correct 422 ms 112376 KB Output is correct
73 Correct 442 ms 112312 KB Output is correct
74 Correct 405 ms 112260 KB Output is correct
75 Correct 408 ms 112248 KB Output is correct
76 Correct 412 ms 112228 KB Output is correct
77 Correct 482 ms 112156 KB Output is correct
78 Correct 423 ms 112320 KB Output is correct
79 Correct 315 ms 112240 KB Output is correct
80 Correct 367 ms 112156 KB Output is correct
81 Correct 329 ms 112248 KB Output is correct
82 Correct 493 ms 112376 KB Output is correct
83 Correct 489 ms 112248 KB Output is correct
84 Correct 320 ms 112108 KB Output is correct
85 Correct 434 ms 112248 KB Output is correct
86 Correct 706 ms 112204 KB Output is correct
87 Correct 472 ms 112160 KB Output is correct
88 Correct 456 ms 112252 KB Output is correct
89 Correct 511 ms 112248 KB Output is correct
90 Correct 360 ms 108664 KB Output is correct
91 Correct 455 ms 112276 KB Output is correct
92 Correct 517 ms 112248 KB Output is correct
93 Correct 755 ms 112196 KB Output is correct
94 Correct 524 ms 112380 KB Output is correct
95 Correct 440 ms 112252 KB Output is correct
96 Correct 436 ms 112248 KB Output is correct
97 Correct 757 ms 112168 KB Output is correct
98 Correct 484 ms 112404 KB Output is correct
99 Correct 502 ms 112128 KB Output is correct
100 Correct 788 ms 112404 KB Output is correct