답안 #706341

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
706341 2023-03-06T09:44:36 Z KiriLL1ca Bomb (IZhO17_bomb) C++17
90 / 100
718 ms 58540 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'
#define sz(x) (int)((x).size())
#define vec vector
#define pw(x) (1ll << x)

using namespace std;
using namespace __gnu_pbds;

template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int inf = 1e9 + 17;

inline void solve () {
    int n, m; cin >> n >> m;
    vec <string> a (n);
    for (auto &i : a) cin >> i;

    vec <int> mx (m + 2, inf);

    for (int iter = 0; iter < 2; ++iter) {
        vec <vec <int>> p (n, vec <int> (m)), s (n, vec <int> (m));
        for (int j = 0; j < m; ++j) {
            p[0][j] = (a[0][j] == '1');
            for (int i = 1; i < n; ++i) {
                if (a[i][j] == '1') p[i][j] = p[i - 1][j] + 1;
            }

            s[n - 1][j] = (a[n - 1][j] == '1');
            for (int i = n - 2; ~i; --i) {
                if (a[i][j] == '1') s[i][j] = s[i + 1][j] + 1;
            }

            for (int i = 0; i < n; ++i) umax(mx[1], p[i][j] + s[i][j] - 1);
        }

        for (int i = 0; i < n; ++i) {
            for (int l = 0, r = 0; r < m; ) {
                while (r < m && a[i][r] == '1') ++r;
                if (l == r) {
                    ++l, ++r;
                    continue;
                }

                int mn_down = inf, mn_up = inf;
                for (int q = l; q < r; ++q) {
                    umin(mn_up, p[i][q]);
                    umin(mn_down, s[i][q]);
                    umin(mx[q - l + 1], mn_down + mn_up - 1);
                }
                umin(mx[r - l + 1], 0);

                l = r;
            }
        }

        for (auto &i : a) reverse(all(i));
    }

    int ans = 0;
    for (int i = 1; i <= m; ++i) {
        umin(mx[i], mx[i - 1]);
//        cout << mx[i] << " " << i << endl;
        umax(ans, mx[i] * i);
    }
    cout << ans << endl;
}

signed main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif// LOCAL
    int t = 1; //cin >> t;
    while (t--) solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 576 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Incorrect 1 ms 324 KB Output isn't correct
27 Incorrect 3 ms 1140 KB Output isn't correct
28 Correct 3 ms 1348 KB Output is correct
29 Correct 4 ms 1508 KB Output is correct
30 Correct 5 ms 2164 KB Output is correct
31 Correct 4 ms 1828 KB Output is correct
32 Correct 4 ms 1900 KB Output is correct
33 Correct 5 ms 2300 KB Output is correct
34 Correct 2 ms 1168 KB Output is correct
35 Correct 5 ms 2312 KB Output is correct
36 Incorrect 6 ms 2352 KB Output isn't correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 718 ms 57812 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 48 ms 8008 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 619 ms 57892 KB Output is correct
44 Correct 6 ms 2288 KB Output is correct
45 Correct 603 ms 57872 KB Output is correct
46 Correct 597 ms 57856 KB Output is correct
47 Correct 600 ms 57716 KB Output is correct
48 Correct 575 ms 57744 KB Output is correct
49 Incorrect 693 ms 57816 KB Output isn't correct
50 Correct 601 ms 57828 KB Output is correct
51 Correct 589 ms 57700 KB Output is correct
52 Correct 548 ms 57708 KB Output is correct
53 Correct 579 ms 57804 KB Output is correct
54 Correct 513 ms 58008 KB Output is correct
55 Correct 495 ms 57952 KB Output is correct
56 Correct 659 ms 58128 KB Output is correct
57 Correct 481 ms 58432 KB Output is correct
58 Correct 482 ms 58540 KB Output is correct
59 Correct 498 ms 58508 KB Output is correct
60 Incorrect 549 ms 58468 KB Output isn't correct
61 Incorrect 632 ms 58212 KB Output isn't correct
62 Incorrect 629 ms 58088 KB Output isn't correct
63 Incorrect 643 ms 58056 KB Output isn't correct
64 Incorrect 451 ms 57968 KB Output isn't correct
65 Correct 498 ms 57980 KB Output is correct
66 Correct 531 ms 57956 KB Output is correct
67 Correct 525 ms 57960 KB Output is correct
68 Correct 560 ms 58052 KB Output is correct
69 Correct 484 ms 57956 KB Output is correct
70 Correct 253 ms 38008 KB Output is correct
71 Correct 420 ms 57992 KB Output is correct
72 Correct 420 ms 57952 KB Output is correct
73 Correct 443 ms 58060 KB Output is correct
74 Correct 466 ms 58112 KB Output is correct
75 Correct 431 ms 58004 KB Output is correct
76 Correct 417 ms 57380 KB Output is correct
77 Correct 459 ms 56948 KB Output is correct
78 Correct 491 ms 56172 KB Output is correct
79 Correct 411 ms 56284 KB Output is correct
80 Correct 421 ms 56168 KB Output is correct
81 Correct 399 ms 56164 KB Output is correct
82 Correct 477 ms 56240 KB Output is correct
83 Correct 445 ms 56076 KB Output is correct
84 Correct 406 ms 56156 KB Output is correct
85 Correct 451 ms 56188 KB Output is correct
86 Correct 578 ms 56224 KB Output is correct
87 Correct 441 ms 56168 KB Output is correct
88 Correct 462 ms 56260 KB Output is correct
89 Correct 512 ms 56232 KB Output is correct
90 Correct 287 ms 36100 KB Output is correct
91 Correct 498 ms 56168 KB Output is correct
92 Correct 510 ms 56184 KB Output is correct
93 Correct 565 ms 56148 KB Output is correct
94 Correct 484 ms 56292 KB Output is correct
95 Correct 449 ms 56164 KB Output is correct
96 Correct 495 ms 56200 KB Output is correct
97 Correct 583 ms 56164 KB Output is correct
98 Correct 484 ms 56208 KB Output is correct
99 Correct 509 ms 56164 KB Output is correct
100 Correct 609 ms 56200 KB Output is correct