Submission #171592

# Submission time Handle Problem Language Result Execution time Memory
171592 2019-12-29T10:27:39 Z mcdx9524 Bomb (IZhO17_bomb) C++14
9 / 100
1000 ms 14344 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2500 + 7;

char a[N][N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    if (n == 1 || m == 1) {
        vector <int> aa;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                char x;
                cin >> x;
                aa.push_back(x - '0');
            }
        }
        int cnt = 1;
        int res = 1e9;
        for (int i = 1; i < max(n, m); i++) {
            if (aa[i] != aa[i - 1]) {
                if (aa[i - 1] == 1) {
                    res = min(res, cnt);
                }
                cnt = 0;
            }
            cnt++;
        }
        if (aa[max(n, m) - 1] == 1) {
            res = min(res, cnt);
        }
        cout << res << '\n';
        return 0;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }
    int ans = 0;
    for (int x = 1; x <= n; x++) {
        for (int y = 1; y <= m; y++) {
            char b[n + 7][m + 7];
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    b[i][j] = a[i][j];
                }
            }
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if (i + x - 1 > n || j + y - 1 > m) {
                        continue;
                    }
                    bool bad = false;
                    for (int r = i; r <= i + x - 1; r++) {
                        for (int c = j; c <= j + y - 1; c++) {
                            if (b[r][c] != '1') {
                                bad = true;
                            }
                            if (bad) break;
                        }
                        if (bad) break;
                    }
                    if (bad) continue;
                    for (int r = i; r <= i + x - 1; r++) {
                        for (int c = j; c <= j + y - 1; c++) {
                            b[r][c] = '2';
                        }
                    }
                }
            }
            for (int i = n; i >= 1; i--) {
                for (int j = m; j >= 1; j--) {
                    if (i - x + 1 < 1 || j - y + 1 < 1) {
                        continue;
                    }
                    if (b[i][j] == '1') {
                        for (int r = i; r >= i - x + 1; r--) {
                            for (int c = j; c >= j - y + 1; c--) {
                                b[i][j] = '2';
                            }
                        }
                    }
                }
            }
            bool good = true;
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if (a[i][j] == '0') {
                        continue;
                    }
                    if (a[i][j] == '1' && b[i][j] == '2') {
                        continue;
                    }
                    good = false;
                    if (!good) break;
                }
                if (!good) break;
            }
            if (good) {
                ans = max(ans, x * y);
            } else {
                break;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Incorrect 2 ms 380 KB Output isn't correct
10 Correct 2 ms 376 KB Output is correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Incorrect 2 ms 376 KB Output isn't correct
13 Incorrect 2 ms 376 KB Output isn't correct
14 Incorrect 2 ms 376 KB Output isn't correct
15 Incorrect 2 ms 376 KB Output isn't correct
16 Incorrect 2 ms 376 KB Output isn't correct
17 Incorrect 6 ms 504 KB Output isn't correct
18 Incorrect 4 ms 508 KB Output isn't correct
19 Incorrect 9 ms 508 KB Output isn't correct
20 Incorrect 9 ms 632 KB Output isn't correct
21 Incorrect 3 ms 508 KB Output isn't correct
22 Correct 5 ms 504 KB Output is correct
23 Incorrect 13 ms 632 KB Output isn't correct
24 Incorrect 7 ms 504 KB Output isn't correct
25 Incorrect 17 ms 632 KB Output isn't correct
26 Incorrect 19 ms 632 KB Output isn't correct
27 Correct 751 ms 1400 KB Output is correct
28 Incorrect 128 ms 1272 KB Output isn't correct
29 Execution timed out 1087 ms 1528 KB Time limit exceeded
30 Execution timed out 1085 ms 1784 KB Time limit exceeded
31 Incorrect 753 ms 1528 KB Output isn't correct
32 Incorrect 834 ms 1656 KB Output isn't correct
33 Execution timed out 1083 ms 1912 KB Time limit exceeded
34 Incorrect 126 ms 1400 KB Output isn't correct
35 Incorrect 588 ms 1912 KB Output isn't correct
36 Execution timed out 1087 ms 1784 KB Time limit exceeded
37 Incorrect 2 ms 376 KB Output isn't correct
38 Execution timed out 1079 ms 14072 KB Time limit exceeded
39 Incorrect 2 ms 376 KB Output isn't correct
40 Execution timed out 1076 ms 3960 KB Time limit exceeded
41 Incorrect 2 ms 476 KB Output isn't correct
42 Incorrect 24 ms 632 KB Output isn't correct
43 Execution timed out 1070 ms 13988 KB Time limit exceeded
44 Execution timed out 1079 ms 1912 KB Time limit exceeded
45 Execution timed out 1075 ms 14040 KB Time limit exceeded
46 Execution timed out 1081 ms 14072 KB Time limit exceeded
47 Execution timed out 1084 ms 13944 KB Time limit exceeded
48 Execution timed out 1087 ms 14072 KB Time limit exceeded
49 Execution timed out 1074 ms 14084 KB Time limit exceeded
50 Execution timed out 1086 ms 14060 KB Time limit exceeded
51 Execution timed out 1087 ms 13944 KB Time limit exceeded
52 Execution timed out 1075 ms 13944 KB Time limit exceeded
53 Execution timed out 1077 ms 14072 KB Time limit exceeded
54 Execution timed out 1077 ms 14072 KB Time limit exceeded
55 Execution timed out 1072 ms 14072 KB Time limit exceeded
56 Execution timed out 1081 ms 14076 KB Time limit exceeded
57 Execution timed out 1073 ms 13944 KB Time limit exceeded
58 Execution timed out 1073 ms 14000 KB Time limit exceeded
59 Execution timed out 1078 ms 13944 KB Time limit exceeded
60 Execution timed out 1072 ms 14072 KB Time limit exceeded
61 Execution timed out 1073 ms 14168 KB Time limit exceeded
62 Execution timed out 1069 ms 14072 KB Time limit exceeded
63 Execution timed out 1062 ms 14072 KB Time limit exceeded
64 Execution timed out 1065 ms 14084 KB Time limit exceeded
65 Execution timed out 1076 ms 14188 KB Time limit exceeded
66 Execution timed out 1083 ms 14072 KB Time limit exceeded
67 Execution timed out 1063 ms 14200 KB Time limit exceeded
68 Execution timed out 1074 ms 14260 KB Time limit exceeded
69 Execution timed out 1066 ms 14232 KB Time limit exceeded
70 Execution timed out 1083 ms 10744 KB Time limit exceeded
71 Execution timed out 1070 ms 14172 KB Time limit exceeded
72 Execution timed out 1079 ms 14200 KB Time limit exceeded
73 Execution timed out 1064 ms 14072 KB Time limit exceeded
74 Execution timed out 1054 ms 14192 KB Time limit exceeded
75 Execution timed out 1071 ms 14072 KB Time limit exceeded
76 Execution timed out 1075 ms 14200 KB Time limit exceeded
77 Execution timed out 1079 ms 14232 KB Time limit exceeded
78 Execution timed out 1065 ms 14200 KB Time limit exceeded
79 Execution timed out 1077 ms 14072 KB Time limit exceeded
80 Execution timed out 1061 ms 14080 KB Time limit exceeded
81 Execution timed out 1076 ms 14200 KB Time limit exceeded
82 Execution timed out 1072 ms 14200 KB Time limit exceeded
83 Execution timed out 1071 ms 14108 KB Time limit exceeded
84 Execution timed out 1078 ms 14200 KB Time limit exceeded
85 Execution timed out 1076 ms 14300 KB Time limit exceeded
86 Execution timed out 1075 ms 14344 KB Time limit exceeded
87 Execution timed out 1071 ms 14312 KB Time limit exceeded
88 Execution timed out 1076 ms 14188 KB Time limit exceeded
89 Execution timed out 1079 ms 14328 KB Time limit exceeded
90 Execution timed out 1082 ms 10872 KB Time limit exceeded
91 Execution timed out 1075 ms 14328 KB Time limit exceeded
92 Execution timed out 1076 ms 14328 KB Time limit exceeded
93 Execution timed out 1091 ms 14328 KB Time limit exceeded
94 Execution timed out 1052 ms 14336 KB Time limit exceeded
95 Execution timed out 1072 ms 14328 KB Time limit exceeded
96 Execution timed out 1080 ms 14204 KB Time limit exceeded
97 Execution timed out 1071 ms 14204 KB Time limit exceeded
98 Execution timed out 1062 ms 14200 KB Time limit exceeded
99 Execution timed out 1083 ms 14240 KB Time limit exceeded
100 Execution timed out 1067 ms 14096 KB Time limit exceeded