Submission #96766

# Submission time Handle Problem Language Result Execution time Memory
96766 2019-02-11T19:29:28 Z choikiwon Bomb (IZhO17_bomb) C++17
99 / 100
880 ms 107108 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(dp(i, j, 0) == 1) {
                    if(len) mn[len - 1] = min(mn[len - 1], tmn);
                    tmn = 1e9;
                    len = 2;
                    continue;
                }
                if(len) {
                    len++;
                    tmn = min(tmn, dp(i, j, 1));
                }
            }
            else tmn = 1e9, len = 0;
        }
        tmn = 1e9;
        len = 0;
        for(int j = 0; j < M; j++) {
            if(G[i][j] == '1') {
                if(dp(i, j, 1) == 1) {
                    if(len) mn[len - 1] = min(mn[len - 1], tmn);
                    tmn = 1e9;
                    len = 2;
                    continue;
                }
                if(len) {
                    len++;
                    tmn = min(tmn, dp(i, j, 0));
                }
            }
            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 76 ms 100216 KB Output is correct
2 Correct 77 ms 100188 KB Output is correct
3 Correct 81 ms 106360 KB Output is correct
4 Correct 71 ms 106360 KB Output is correct
5 Correct 77 ms 100088 KB Output is correct
6 Correct 77 ms 100088 KB Output is correct
7 Correct 77 ms 100088 KB Output is correct
8 Correct 77 ms 100216 KB Output is correct
9 Correct 67 ms 100216 KB Output is correct
10 Correct 78 ms 100216 KB Output is correct
11 Correct 69 ms 100216 KB Output is correct
12 Correct 66 ms 100216 KB Output is correct
13 Correct 67 ms 100216 KB Output is correct
14 Correct 70 ms 100216 KB Output is correct
15 Correct 69 ms 100292 KB Output is correct
16 Correct 70 ms 100216 KB Output is correct
17 Correct 69 ms 100344 KB Output is correct
18 Correct 68 ms 100344 KB Output is correct
19 Correct 82 ms 100344 KB Output is correct
20 Correct 69 ms 100344 KB Output is correct
21 Correct 75 ms 100324 KB Output is correct
22 Correct 70 ms 100348 KB Output is correct
23 Correct 70 ms 100344 KB Output is correct
24 Correct 69 ms 100344 KB Output is correct
25 Correct 70 ms 100344 KB Output is correct
26 Correct 74 ms 100344 KB Output is correct
27 Correct 81 ms 100856 KB Output is correct
28 Correct 73 ms 100856 KB Output is correct
29 Correct 83 ms 101240 KB Output is correct
30 Correct 95 ms 101160 KB Output is correct
31 Correct 86 ms 100984 KB Output is correct
32 Correct 86 ms 101156 KB Output is correct
33 Correct 91 ms 101232 KB Output is correct
34 Correct 82 ms 100984 KB Output is correct
35 Correct 89 ms 101240 KB Output is correct
36 Correct 108 ms 101288 KB Output is correct
37 Correct 78 ms 100188 KB Output is correct
38 Correct 860 ms 107104 KB Output is correct
39 Correct 69 ms 100216 KB Output is correct
40 Incorrect 163 ms 102520 KB Output isn't correct
41 Correct 78 ms 100216 KB Output is correct
42 Correct 79 ms 100344 KB Output is correct
43 Correct 733 ms 106796 KB Output is correct
44 Correct 99 ms 101240 KB Output is correct
45 Correct 615 ms 106976 KB Output is correct
46 Correct 517 ms 106744 KB Output is correct
47 Correct 657 ms 106988 KB Output is correct
48 Correct 548 ms 107000 KB Output is correct
49 Correct 842 ms 106892 KB Output is correct
50 Correct 573 ms 106872 KB Output is correct
51 Correct 582 ms 106912 KB Output is correct
52 Correct 570 ms 106872 KB Output is correct
53 Correct 541 ms 106872 KB Output is correct
54 Correct 466 ms 106744 KB Output is correct
55 Correct 464 ms 106744 KB Output is correct
56 Correct 845 ms 106872 KB Output is correct
57 Correct 464 ms 106872 KB Output is correct
58 Correct 452 ms 106872 KB Output is correct
59 Correct 451 ms 106812 KB Output is correct
60 Correct 613 ms 106848 KB Output is correct
61 Correct 858 ms 107108 KB Output is correct
62 Correct 776 ms 106872 KB Output is correct
63 Correct 880 ms 106872 KB Output is correct
64 Correct 453 ms 106844 KB Output is correct
65 Correct 584 ms 106956 KB Output is correct
66 Correct 555 ms 106872 KB Output is correct
67 Correct 686 ms 106920 KB Output is correct
68 Correct 672 ms 106748 KB Output is correct
69 Correct 460 ms 106876 KB Output is correct
70 Correct 262 ms 105592 KB Output is correct
71 Correct 391 ms 106816 KB Output is correct
72 Correct 433 ms 106748 KB Output is correct
73 Correct 454 ms 106876 KB Output is correct
74 Correct 461 ms 106744 KB Output is correct
75 Correct 424 ms 106744 KB Output is correct
76 Correct 442 ms 106920 KB Output is correct
77 Correct 464 ms 106892 KB Output is correct
78 Correct 523 ms 106872 KB Output is correct
79 Correct 364 ms 106972 KB Output is correct
80 Correct 335 ms 106872 KB Output is correct
81 Correct 333 ms 106756 KB Output is correct
82 Correct 492 ms 106824 KB Output is correct
83 Correct 538 ms 106872 KB Output is correct
84 Correct 317 ms 106716 KB Output is correct
85 Correct 452 ms 106872 KB Output is correct
86 Correct 775 ms 106948 KB Output is correct
87 Correct 430 ms 106876 KB Output is correct
88 Correct 447 ms 106744 KB Output is correct
89 Correct 547 ms 106844 KB Output is correct
90 Correct 347 ms 105592 KB Output is correct
91 Correct 505 ms 106788 KB Output is correct
92 Correct 527 ms 106912 KB Output is correct
93 Correct 769 ms 106748 KB Output is correct
94 Correct 558 ms 107000 KB Output is correct
95 Correct 473 ms 106860 KB Output is correct
96 Correct 478 ms 106872 KB Output is correct
97 Correct 774 ms 106872 KB Output is correct
98 Correct 478 ms 106832 KB Output is correct
99 Correct 530 ms 106804 KB Output is correct
100 Correct 750 ms 106872 KB Output is correct