Submission #96765

# Submission time Handle Problem Language Result Execution time Memory
96765 2019-02-11T19:26:15 Z choikiwon Bomb (IZhO17_bomb) C++17
99 / 100
921 ms 107896 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 chk1 = 0, chk2 = 0;
        for(int j = 0; j < M; j++) {
            if(G[i][j] == '1') {
                if(dp(i, j, 3) == 1) {
                    len = 1;
                }
                if(len) {
                    if(dp(i, j, 0) == 1) chk1 = 1;
                    if(chk1) mn[len] = min(mn[len], dp(i, j, 1));
                    if(dp(i, j, 1) == 1) chk2 = 1;
                    if(chk2) mn[len] = min(mn[len], dp(i, j, 0));
                }
                len++;
            }
            else len = 0, chk1 = 0, chk2 = 0;
        }
        len = 0;
        chk1 = 0, chk2 = 0;
        for(int j = M - 1; j >= 0; j--) {
            if(G[i][j] == '1') {
                if(dp(i, j, 2) == 1) {
                    len = 1;
                }
                if(len) {
                    if(dp(i, j, 0) == 1) chk1 = 1;
                    if(chk1) mn[len] = min(mn[len], dp(i, j, 1));
                    if(dp(i, j, 1) == 1) chk2 = 1;
                    if(chk2) mn[len] = min(mn[len], dp(i, j, 0));
                }
                len++;
            }
            else len = 0, chk1 = 0, chk2 = 0;
        }
    }
    /*
    for(int i = 0; i < N; i++) {
        int tmn = 1e9;
        int len = 0;
        for(int j = 0; j < M; j++) {
            if(G[i][j] == '1') {
                if(len) tmn = min(tmn, dp(i, j, 1));
                if(dp(i, j, 0) == 1) {
                    if(len) mn[len - 1] = min(mn[len - 1], tmn);
                    tmn = dp(i, j, 1);
                    len = 1;
                }
                if(len) len++;
            }
            else tmn = 1e9, len = 0;
        }
        tmn = 1e9;
        len = 0;
        for(int j = 0; j < M; j++) {
            if(G[i][j] == '1') {
                if(len) tmn = min(tmn, dp(i, j, 0));
                if(dp(i, j, 1) == 1) {
                    if(len) mn[len - 1] = min(mn[len - 1], tmn);
                    tmn = dp(i, j, 0);
                    len = 1;
                }
                if(len) len++;
            }
            else tmn = 1e9, len = 0;
        }
    }
    //*/

    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 68 ms 100188 KB Output is correct
2 Correct 67 ms 100216 KB Output is correct
3 Correct 71 ms 106360 KB Output is correct
4 Correct 71 ms 106360 KB Output is correct
5 Correct 70 ms 100216 KB Output is correct
6 Correct 68 ms 100152 KB Output is correct
7 Correct 68 ms 100088 KB Output is correct
8 Correct 78 ms 100188 KB Output is correct
9 Correct 69 ms 100188 KB Output is correct
10 Correct 68 ms 100160 KB Output is correct
11 Correct 78 ms 100316 KB Output is correct
12 Correct 78 ms 100216 KB Output is correct
13 Correct 79 ms 100216 KB Output is correct
14 Correct 79 ms 100216 KB Output is correct
15 Correct 78 ms 100216 KB Output is correct
16 Correct 81 ms 100216 KB Output is correct
17 Correct 82 ms 100256 KB Output is correct
18 Correct 89 ms 100348 KB Output is correct
19 Correct 79 ms 100344 KB Output is correct
20 Correct 78 ms 100344 KB Output is correct
21 Correct 79 ms 100344 KB Output is correct
22 Correct 68 ms 100300 KB Output is correct
23 Correct 78 ms 100316 KB Output is correct
24 Correct 69 ms 100396 KB Output is correct
25 Correct 69 ms 100344 KB Output is correct
26 Correct 69 ms 100344 KB Output is correct
27 Correct 76 ms 100856 KB Output is correct
28 Correct 74 ms 100856 KB Output is correct
29 Correct 80 ms 101112 KB Output is correct
30 Correct 79 ms 101240 KB Output is correct
31 Correct 75 ms 100984 KB Output is correct
32 Correct 79 ms 101212 KB Output is correct
33 Correct 82 ms 101240 KB Output is correct
34 Correct 72 ms 100984 KB Output is correct
35 Correct 76 ms 101240 KB Output is correct
36 Correct 103 ms 101240 KB Output is correct
37 Correct 78 ms 100216 KB Output is correct
38 Correct 832 ms 107564 KB Output is correct
39 Correct 77 ms 100216 KB Output is correct
40 Incorrect 158 ms 102904 KB Output isn't correct
41 Correct 78 ms 100216 KB Output is correct
42 Correct 78 ms 100316 KB Output is correct
43 Correct 679 ms 107612 KB Output is correct
44 Correct 93 ms 101236 KB Output is correct
45 Correct 605 ms 107640 KB Output is correct
46 Correct 496 ms 107720 KB Output is correct
47 Correct 605 ms 107896 KB Output is correct
48 Correct 538 ms 107768 KB Output is correct
49 Correct 800 ms 107568 KB Output is correct
50 Correct 542 ms 107640 KB Output is correct
51 Correct 543 ms 107744 KB Output is correct
52 Correct 550 ms 107596 KB Output is correct
53 Correct 536 ms 107652 KB Output is correct
54 Correct 468 ms 107780 KB Output is correct
55 Correct 444 ms 107640 KB Output is correct
56 Correct 777 ms 107628 KB Output is correct
57 Correct 484 ms 107612 KB Output is correct
58 Correct 485 ms 107812 KB Output is correct
59 Correct 507 ms 107640 KB Output is correct
60 Correct 579 ms 107680 KB Output is correct
61 Correct 921 ms 107832 KB Output is correct
62 Correct 788 ms 107780 KB Output is correct
63 Correct 861 ms 107768 KB Output is correct
64 Correct 463 ms 107740 KB Output is correct
65 Correct 545 ms 107768 KB Output is correct
66 Correct 560 ms 107788 KB Output is correct
67 Correct 579 ms 107640 KB Output is correct
68 Correct 646 ms 107768 KB Output is correct
69 Correct 422 ms 107768 KB Output is correct
70 Correct 271 ms 106376 KB Output is correct
71 Correct 396 ms 107636 KB Output is correct
72 Correct 445 ms 107568 KB Output is correct
73 Correct 452 ms 107492 KB Output is correct
74 Correct 433 ms 107356 KB Output is correct
75 Correct 431 ms 107384 KB Output is correct
76 Correct 444 ms 107368 KB Output is correct
77 Correct 455 ms 107472 KB Output is correct
78 Correct 454 ms 107432 KB Output is correct
79 Correct 332 ms 107292 KB Output is correct
80 Correct 330 ms 107384 KB Output is correct
81 Correct 346 ms 107384 KB Output is correct
82 Correct 454 ms 107256 KB Output is correct
83 Correct 468 ms 107160 KB Output is correct
84 Correct 382 ms 107176 KB Output is correct
85 Correct 435 ms 107180 KB Output is correct
86 Correct 735 ms 107256 KB Output is correct
87 Correct 422 ms 107180 KB Output is correct
88 Correct 444 ms 107384 KB Output is correct
89 Correct 561 ms 107128 KB Output is correct
90 Correct 306 ms 105976 KB Output is correct
91 Correct 500 ms 107128 KB Output is correct
92 Correct 536 ms 107092 KB Output is correct
93 Correct 746 ms 107004 KB Output is correct
94 Correct 537 ms 106972 KB Output is correct
95 Correct 446 ms 107036 KB Output is correct
96 Correct 452 ms 107000 KB Output is correct
97 Correct 885 ms 106904 KB Output is correct
98 Correct 463 ms 106992 KB Output is correct
99 Correct 608 ms 106948 KB Output is correct
100 Correct 805 ms 106928 KB Output is correct