Submission #173276

# Submission time Handle Problem Language Result Execution time Memory
173276 2020-01-03T17:35:37 Z apostoldaniel854 Bomb (IZhO17_bomb) C++14
100 / 100
508 ms 55672 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2500;

char a[1 + N][1 + N];
int lst[1 + N + 1][1 + N + 1];
int nxt[1 + N + 1][1 + N + 1];
int best[1 + N];

int main () {
   // freopen ("bomb.in", "r", stdin);
  //  freopen ("bomb.out", "w", stdout);

    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);

    int n, m;
    cin >> n >> m;

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j], a[i][j] -= '0';

    int mxl = n;
    for (int j = 1; j <= m; j++)
        for (int i = 1; i <= n; i++) {
            if (a[i][j] == 0)
                continue;
            int k = i;
            while (k <= n && a[k + 1][j] == 1)
                k++;
            mxl = min (mxl, k - i + 1);
            i = k;
        }
    int mxc = m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            if (a[i][j] == 0)
                continue;
            int k = j;
            while (k <= m && a[i][k + 1] == 1)
                k++;
            mxc = min (mxc, k - j + 1);
            j = k;
        }

    for (int i = 1; i <= n; i++) {
        lst[i][0] = 1;
        for (int j = 1; j <= m; j++) {
            lst[i][j] = lst[i][j - 1];
            if (a[i][j] == 0)
                lst[i][j] = j + 1;
        }
        nxt[i][m + 1] = m;
        for (int j = m; j > 0; j--) {
            nxt[i][j] = nxt[i][j + 1];
            if (a[i][j] == 0)
                nxt[i][j] = j - 1;
        }
    }

    for (int i = 1; i <= n; i++)
        best[i] = m + 1;

    for (int j = 1; j <= m; j++) {
        int cur = 0;
        int l = 0, r = m + 1;
        for (int i = 1; i <= n; i++) {
            if (a[i][j] == 0) {
                cur = 0;
                l = 0, r = m + 1;
            }
            else {
                cur++;
                l = max (l, lst[i][j]);
                r = min (r, nxt[i][j]);
                best[cur] = min (best[cur], r - l + 1);
            }
        }
        cur = 0;
        l = 0, r = m + 1;
        for (int i = n; i > 0; i--) {
            if (a[i][j] == 0) {
                cur = 0;
                l = 0, r = m + 1;
            }
            else {
                cur++;
                l = max (l, lst[i][j]);
                r = min (r, nxt[i][j]);
                best[cur] = min (best[cur], r - l + 1);
            }
        }
    }

    int ans = 0;
    for (int i = 1; i <= mxl; i++)
        ans = max (ans, min (mxc, best[i]) * i);
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 22 ms 26616 KB Output is correct
4 Correct 22 ms 26616 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 508 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 632 KB Output is correct
17 Correct 2 ms 1016 KB Output is correct
18 Correct 2 ms 1144 KB Output is correct
19 Correct 3 ms 1400 KB Output is correct
20 Correct 3 ms 1400 KB Output is correct
21 Correct 2 ms 888 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 3 ms 1400 KB Output is correct
24 Correct 3 ms 1272 KB Output is correct
25 Correct 3 ms 1528 KB Output is correct
26 Correct 3 ms 1528 KB Output is correct
27 Correct 7 ms 4088 KB Output is correct
28 Correct 7 ms 4344 KB Output is correct
29 Correct 9 ms 5496 KB Output is correct
30 Correct 11 ms 6392 KB Output is correct
31 Correct 9 ms 5112 KB Output is correct
32 Correct 10 ms 5880 KB Output is correct
33 Correct 12 ms 6648 KB Output is correct
34 Correct 7 ms 4732 KB Output is correct
35 Correct 11 ms 6648 KB Output is correct
36 Correct 12 ms 6648 KB Output is correct
37 Correct 2 ms 632 KB Output is correct
38 Correct 506 ms 55556 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 52 ms 15628 KB Output is correct
41 Correct 2 ms 632 KB Output is correct
42 Correct 3 ms 1400 KB Output is correct
43 Correct 399 ms 55468 KB Output is correct
44 Correct 13 ms 6648 KB Output is correct
45 Correct 391 ms 55516 KB Output is correct
46 Correct 363 ms 55416 KB Output is correct
47 Correct 390 ms 55576 KB Output is correct
48 Correct 371 ms 55416 KB Output is correct
49 Correct 499 ms 55672 KB Output is correct
50 Correct 378 ms 55672 KB Output is correct
51 Correct 399 ms 55416 KB Output is correct
52 Correct 371 ms 55488 KB Output is correct
53 Correct 369 ms 55492 KB Output is correct
54 Correct 296 ms 55416 KB Output is correct
55 Correct 303 ms 55544 KB Output is correct
56 Correct 489 ms 55416 KB Output is correct
57 Correct 296 ms 55544 KB Output is correct
58 Correct 289 ms 55416 KB Output is correct
59 Correct 284 ms 55416 KB Output is correct
60 Correct 360 ms 55544 KB Output is correct
61 Correct 506 ms 55544 KB Output is correct
62 Correct 506 ms 55544 KB Output is correct
63 Correct 508 ms 55592 KB Output is correct
64 Correct 291 ms 55432 KB Output is correct
65 Correct 359 ms 55420 KB Output is correct
66 Correct 363 ms 55480 KB Output is correct
67 Correct 410 ms 55468 KB Output is correct
68 Correct 428 ms 55672 KB Output is correct
69 Correct 284 ms 55416 KB Output is correct
70 Correct 171 ms 44464 KB Output is correct
71 Correct 250 ms 55424 KB Output is correct
72 Correct 277 ms 55388 KB Output is correct
73 Correct 286 ms 55508 KB Output is correct
74 Correct 279 ms 55544 KB Output is correct
75 Correct 285 ms 55544 KB Output is correct
76 Correct 308 ms 55476 KB Output is correct
77 Correct 300 ms 55416 KB Output is correct
78 Correct 297 ms 55672 KB Output is correct
79 Correct 212 ms 55544 KB Output is correct
80 Correct 247 ms 55416 KB Output is correct
81 Correct 217 ms 55544 KB Output is correct
82 Correct 301 ms 55544 KB Output is correct
83 Correct 300 ms 55416 KB Output is correct
84 Correct 207 ms 55548 KB Output is correct
85 Correct 290 ms 55544 KB Output is correct
86 Correct 474 ms 55516 KB Output is correct
87 Correct 281 ms 55460 KB Output is correct
88 Correct 299 ms 55592 KB Output is correct
89 Correct 344 ms 55544 KB Output is correct
90 Correct 173 ms 44536 KB Output is correct
91 Correct 308 ms 55424 KB Output is correct
92 Correct 354 ms 55416 KB Output is correct
93 Correct 462 ms 55416 KB Output is correct
94 Correct 347 ms 55672 KB Output is correct
95 Correct 299 ms 55556 KB Output is correct
96 Correct 298 ms 55444 KB Output is correct
97 Correct 471 ms 55540 KB Output is correct
98 Correct 299 ms 55500 KB Output is correct
99 Correct 340 ms 55544 KB Output is correct
100 Correct 451 ms 55420 KB Output is correct