Submission #100304

# Submission time Handle Problem Language Result Execution time Memory
100304 2019-03-10T10:45:08 Z naoai Bomb (IZhO17_bomb) C++14
92 / 100
642 ms 68088 KB
#include <bits/stdc++.h>

using namespace std;

#define fin cin
#define fout cout
//ifstream fin("x.in"); ofstream fout("x.out");

const int nmax = 2500 + 5;
const int inf = 1 << 30;

int n, m;
int v[nmax + 1][nmax + 1];
int u[nmax + 1][nmax + 1];

int w[nmax + 1];
int st[nmax + 1][nmax + 1], dr[nmax + 1][nmax + 1];
string s[nmax + 1];

void check (int h, int w) {
    for (int i = 1; i <= n; ++ i) {
        for (int j = 1; j <= m; ++ j) {
            v[i][j] = v[i - 1][j] + v[i][j - 1] - v[i - 1][j - 1] + (s[i][j - 1] - '0');
        }
    }

    bool ok = 1;
    for (int i = 1; i <= n - h + 1; ++ i) {
        for (int j = 1; j <= m - w + 1; ++ j) {
            int sum = v[i + h - 1][j + w - 1] - v[i - 1][j + w - 1] - v[i + h - 1][j - 1] + v[i - 1][j - 1];
            if (sum == h * w) {
                ++ u[i][j];
                ++ u[i + h][j + w];
                -- u[i + h][j];
                -- u[i][j + w];
            }
        }
    }

    for (int i = 1; i <= n; ++ i) {
        for (int j = 1; j <= m; ++ j) {
            u[i][j] += u[i - 1][j] + u[i][j - 1] - u[i - 1][j - 1];
            if ((u[i][j] == 0) != ((s[i][j - 1] - '0') == 0)) {
                assert(0);
            }
        }
    }
}

int main() {
    fin.sync_with_stdio(false); fin.tie(); fout.tie();
    fin >> n >> m;

    for (int i = 1; i <= n; ++ i)
        fin >> s[i];

    for (int i = 1; i <= n; ++ i) {
        s[i] = '0' + s[i] + '0';
    }

    s[0].resize(m + 2, '0');
    s[n + 1].resize(m + 2, '0');

    for (int i = 1; i <= n; ++ i) {
        st[i][0] = 1;
        for (int j = 1; j <= m; ++ j) {
            if (s[i][j] == '1')
                st[i][j] = st[i][j - 1];
            else
                st[i][j] = j + 1;
        }

        dr[i][m + 1] = m;
        for (int j = m; j > 0; -- j) {
            if (s[i][j] == '1')
                dr[i][j] = dr[i][j + 1];
            else
                dr[i][j] = j - 1;
        }
    }

    for (int i = 1; i <= n; ++ i)
        w[i] = inf;

    for (int i = 1; i <= n; ++ i) {
        for (int j = 1; j <= m; ++ j) {
            if (s[i - 1][j] == '0' && s[i][j] == '1') {
                int k = i;
                int mn = st[i][j], mx = dr[i][j];

                while (k <= m && s[k][j] == '1') {
                    mn = max(mn, st[k][j]);
                    mx = min(mx, dr[k][j]);
                    w[k - i + 1] = min(w[k - i + 1], mx - mn + 1);
                    ++ k;
                }
            }
        }

        for (int j = 1; j <= m; ++ j) {
            if (s[i + 1][j] == '0' && s[i][j] == '1') {
                int k = i;
                int mn = st[i][j], mx = dr[i][j];

                while (k > 0 && s[k][j] == '1') {
                    mn = max(mn, st[k][j]);
                    mx = min(mx, dr[k][j]);
                    w[i - k + 1] = min(w[i - k + 1], mx - mn + 1);
                    -- k;
                }
            }
        }
    }

    int h = inf;
    for (int j = 1; j <= m; ++ j) {
        int cnt = 0;
        for (int i = 1; i <= n; ++ i) {
            if (s[i][j] == '1')
                ++ cnt;
            else
                cnt = 0;

            if (s[i][j] == '1' && s[i + 1][j] == '0')
                h = min(h, cnt);
        }
    }

    int amax = 0;
    for (int i = 1; i <= h; ++ i) {
        if (w[i] != inf)
            amax = max(amax, i * w[i]);
    }

    cout << amax << "\n";

    return 0;
}

Compilation message

bomb.cpp: In function 'void check(int, int)':
bomb.cpp:27:10: warning: unused variable 'ok' [-Wunused-variable]
     bool ok = 1;
          ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 484 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 16 ms 20480 KB Output is correct
4 Correct 20 ms 20608 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Incorrect 3 ms 512 KB Output isn't correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 1024 KB Output is correct
18 Correct 3 ms 1024 KB Output is correct
19 Correct 3 ms 1280 KB Output is correct
20 Correct 3 ms 1280 KB Output is correct
21 Correct 2 ms 896 KB Output is correct
22 Correct 3 ms 1152 KB Output is correct
23 Correct 3 ms 1408 KB Output is correct
24 Correct 3 ms 1152 KB Output is correct
25 Correct 3 ms 1280 KB Output is correct
26 Incorrect 4 ms 1408 KB Output isn't correct
27 Incorrect 7 ms 3712 KB Output isn't correct
28 Correct 7 ms 3968 KB Output is correct
29 Correct 7 ms 4992 KB Output is correct
30 Correct 8 ms 5888 KB Output is correct
31 Correct 7 ms 4736 KB Output is correct
32 Correct 7 ms 5376 KB Output is correct
33 Correct 10 ms 6272 KB Output is correct
34 Correct 6 ms 4224 KB Output is correct
35 Correct 8 ms 6324 KB Output is correct
36 Incorrect 12 ms 6272 KB Output isn't correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 572 ms 67956 KB Output is correct
39 Correct 3 ms 640 KB Output is correct
40 Correct 42 ms 15744 KB Output is correct
41 Correct 2 ms 640 KB Output is correct
42 Correct 3 ms 1408 KB Output is correct
43 Correct 432 ms 67832 KB Output is correct
44 Correct 10 ms 6272 KB Output is correct
45 Correct 398 ms 67924 KB Output is correct
46 Correct 227 ms 67832 KB Output is correct
47 Correct 424 ms 67832 KB Output is correct
48 Correct 403 ms 67832 KB Output is correct
49 Incorrect 642 ms 67960 KB Output isn't correct
50 Correct 425 ms 67960 KB Output is correct
51 Correct 422 ms 67832 KB Output is correct
52 Correct 418 ms 68088 KB Output is correct
53 Correct 405 ms 67832 KB Output is correct
54 Correct 264 ms 67964 KB Output is correct
55 Correct 259 ms 67832 KB Output is correct
56 Correct 621 ms 67964 KB Output is correct
57 Correct 265 ms 67928 KB Output is correct
58 Correct 294 ms 67996 KB Output is correct
59 Correct 258 ms 67832 KB Output is correct
60 Correct 356 ms 68048 KB Output is correct
61 Incorrect 583 ms 67960 KB Output isn't correct
62 Incorrect 536 ms 67832 KB Output isn't correct
63 Incorrect 626 ms 67960 KB Output isn't correct
64 Correct 240 ms 67832 KB Output is correct
65 Correct 359 ms 67832 KB Output is correct
66 Correct 364 ms 67960 KB Output is correct
67 Correct 404 ms 67804 KB Output is correct
68 Correct 436 ms 67832 KB Output is correct
69 Correct 288 ms 67960 KB Output is correct
70 Correct 103 ms 51448 KB Output is correct
71 Correct 187 ms 67892 KB Output is correct
72 Correct 217 ms 67832 KB Output is correct
73 Correct 244 ms 67960 KB Output is correct
74 Correct 210 ms 67836 KB Output is correct
75 Correct 222 ms 67832 KB Output is correct
76 Correct 232 ms 67832 KB Output is correct
77 Correct 293 ms 67832 KB Output is correct
78 Correct 238 ms 67832 KB Output is correct
79 Correct 147 ms 68088 KB Output is correct
80 Correct 140 ms 67832 KB Output is correct
81 Correct 141 ms 67960 KB Output is correct
82 Correct 257 ms 67908 KB Output is correct
83 Correct 228 ms 67832 KB Output is correct
84 Correct 130 ms 67960 KB Output is correct
85 Correct 226 ms 67932 KB Output is correct
86 Correct 566 ms 67892 KB Output is correct
87 Correct 226 ms 67960 KB Output is correct
88 Correct 242 ms 67832 KB Output is correct
89 Correct 318 ms 67832 KB Output is correct
90 Correct 126 ms 51448 KB Output is correct
91 Correct 263 ms 67832 KB Output is correct
92 Correct 323 ms 67832 KB Output is correct
93 Correct 508 ms 67960 KB Output is correct
94 Correct 372 ms 67832 KB Output is correct
95 Correct 234 ms 67964 KB Output is correct
96 Correct 233 ms 67832 KB Output is correct
97 Correct 565 ms 67960 KB Output is correct
98 Correct 256 ms 67960 KB Output is correct
99 Correct 348 ms 68036 KB Output is correct
100 Correct 544 ms 67832 KB Output is correct