답안 #1030391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030391 2024-07-22T04:30:24 Z caterpillow Bomb (IZhO17_bomb) C++17
49 / 100
1000 ms 57056 KB
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using ll = long long;
#define vt vector
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define FOR(i, a, b)  for (int i = (a); i < (b); i++)
#define F0R(i, b) FOR(i, 0, b)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define pb push_back
#define endl '\n'

#ifndef LOCAL
#define cerr if (0) std::cerr
#endif

/*

N^3: find max width for each given height

*/

int rs, cs;
vt<vt<bool>> grid;
vt<vt<int>> sfx;

int sum(int r1, int c1, int r2, int c2) {
    r2 = min(r2, rs - 1);
    c2 = min(c2, cs - 1);
    return sfx[r1][c1] - sfx[r1][c2 + 1] - sfx[r2 + 1][c1] + sfx[r2 + 1][c2 + 1];
}


bool check(int w, int h) {
    vt<vt<int>> pfx(rs, vt<int>(cs));
    auto is_covered = [&] (int r, int c) {
        return (pfx[r][c] - (r - h >= 0 ? pfx[r - h][c] : 0) - (c - w >= 0 ? pfx[r][c - w] : 0) + (r - h >= 0 && c - w >= 0 ? pfx[r - h][c - w] : 0)) > 0;
    };
    auto add = [&] (int r, int c) {
        pfx[r][c] += (r ? pfx[r - 1][c] : 0) + (c ? pfx[r][c - 1] : 0) - (r && c ? pfx[r - 1][c - 1] : 0);
    };

    F0R (r, rs - 1) {
        F0R (c, cs - 1) {
            if (sum(r, c, r + h - 1, c + w - 1) == w * h) {
                pfx[r][c]++;
            }
            add(r, c);
            if (grid[r][c] == 1) {
                if (!is_covered(r, c)) return false;
            }
        }
    }
    return true;
}

main() {
    cin.tie(0)->sync_with_stdio();

    cin >> rs >> cs;
    rs += 2, cs += 2;
    grid.resize(rs, vt<bool>(cs));
    sfx.resize(rs + 1, vt<int>(cs + 1));
    FOR (r, 1, rs - 1) {
        FOR (c, 1, cs - 1) {
            char ch; cin >> ch;
            grid[r][c] = sfx[r][c] = ch - '0';
        }
    }
    ROF (r, 0, rs) ROF (c, 0, cs) sfx[r][c] += sfx[r][c + 1];
    ROF (r, 0, rs) ROF (c, 0, cs) sfx[r][c] += sfx[r + 1][c];

    int mxw = cs, mxh = rs;
    F0R (r, rs) {
        int streak = 0;
        F0R (c, cs) {
            if (grid[r][c]) streak++;
            else if (streak) mxw = min(mxw, streak), streak = 0;
        }
    }
    F0R (c, cs) {
        int streak = 0;
        F0R (r, rs) {
            if (grid[r][c]) streak++;
            else if (streak) mxh = min(mxh, streak), streak = 0;
        }
    }

    int ans = max(mxh, mxw);
    int w = mxw;
    FOR (h, 2, mxh + 1) {
        while (w != 1 && !check(w, h)) {
            w--;
        }
        ans = max(w * h, ans);
    }
    cout << ans << endl;
}

Compilation message

bomb.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | main() {
      | ^~~~
bomb.cpp: In function 'int main()':
bomb.cpp:73:36: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   73 |             grid[r][c] = sfx[r][c] = ch - '0';
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 692 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 436 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 352 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 352 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 352 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 356 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 9 ms 1480 KB Output is correct
29 Correct 63 ms 1788 KB Output is correct
30 Correct 80 ms 2440 KB Output is correct
31 Correct 54 ms 2104 KB Output is correct
32 Correct 33 ms 1896 KB Output is correct
33 Correct 80 ms 2304 KB Output is correct
34 Correct 5 ms 1220 KB Output is correct
35 Correct 45 ms 2860 KB Output is correct
36 Correct 64 ms 2316 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Execution timed out 1033 ms 56696 KB Time limit exceeded
39 Correct 0 ms 352 KB Output is correct
40 Execution timed out 1055 ms 7836 KB Time limit exceeded
41 Correct 0 ms 348 KB Output is correct
42 Correct 3 ms 536 KB Output is correct
43 Execution timed out 1091 ms 56756 KB Time limit exceeded
44 Correct 302 ms 2316 KB Output is correct
45 Execution timed out 1052 ms 56924 KB Time limit exceeded
46 Correct 922 ms 56700 KB Output is correct
47 Execution timed out 1052 ms 56708 KB Time limit exceeded
48 Execution timed out 1053 ms 56704 KB Time limit exceeded
49 Correct 339 ms 56704 KB Output is correct
50 Execution timed out 1037 ms 56836 KB Time limit exceeded
51 Execution timed out 1066 ms 56744 KB Time limit exceeded
52 Execution timed out 1033 ms 57012 KB Time limit exceeded
53 Execution timed out 1031 ms 56672 KB Time limit exceeded
54 Execution timed out 1076 ms 56724 KB Time limit exceeded
55 Execution timed out 1042 ms 56704 KB Time limit exceeded
56 Execution timed out 1038 ms 56696 KB Time limit exceeded
57 Execution timed out 1014 ms 56724 KB Time limit exceeded
58 Execution timed out 1076 ms 56892 KB Time limit exceeded
59 Execution timed out 1065 ms 56872 KB Time limit exceeded
60 Correct 982 ms 56744 KB Output is correct
61 Correct 746 ms 56584 KB Output is correct
62 Execution timed out 1092 ms 56696 KB Time limit exceeded
63 Execution timed out 1057 ms 56692 KB Time limit exceeded
64 Execution timed out 1034 ms 56868 KB Time limit exceeded
65 Execution timed out 1048 ms 56740 KB Time limit exceeded
66 Correct 485 ms 56708 KB Output is correct
67 Execution timed out 1065 ms 56832 KB Time limit exceeded
68 Execution timed out 1018 ms 56784 KB Time limit exceeded
69 Execution timed out 1018 ms 56912 KB Time limit exceeded
70 Execution timed out 1074 ms 36880 KB Time limit exceeded
71 Execution timed out 1014 ms 56796 KB Time limit exceeded
72 Execution timed out 1057 ms 56748 KB Time limit exceeded
73 Execution timed out 1068 ms 56784 KB Time limit exceeded
74 Execution timed out 1062 ms 56752 KB Time limit exceeded
75 Execution timed out 1089 ms 56812 KB Time limit exceeded
76 Execution timed out 1062 ms 56732 KB Time limit exceeded
77 Execution timed out 1022 ms 56748 KB Time limit exceeded
78 Execution timed out 1063 ms 56900 KB Time limit exceeded
79 Execution timed out 1038 ms 56736 KB Time limit exceeded
80 Execution timed out 1054 ms 57000 KB Time limit exceeded
81 Execution timed out 1041 ms 56844 KB Time limit exceeded
82 Execution timed out 1067 ms 56744 KB Time limit exceeded
83 Execution timed out 1074 ms 56808 KB Time limit exceeded
84 Execution timed out 1066 ms 56796 KB Time limit exceeded
85 Execution timed out 1053 ms 56732 KB Time limit exceeded
86 Correct 801 ms 56884 KB Output is correct
87 Execution timed out 1042 ms 56796 KB Time limit exceeded
88 Execution timed out 1065 ms 56724 KB Time limit exceeded
89 Execution timed out 1066 ms 56992 KB Time limit exceeded
90 Execution timed out 1070 ms 36552 KB Time limit exceeded
91 Execution timed out 1022 ms 56892 KB Time limit exceeded
92 Execution timed out 1043 ms 56784 KB Time limit exceeded
93 Execution timed out 1008 ms 57056 KB Time limit exceeded
94 Execution timed out 1059 ms 56792 KB Time limit exceeded
95 Execution timed out 1031 ms 56852 KB Time limit exceeded
96 Execution timed out 1083 ms 56892 KB Time limit exceeded
97 Correct 920 ms 56872 KB Output is correct
98 Execution timed out 1050 ms 56980 KB Time limit exceeded
99 Execution timed out 1069 ms 56748 KB Time limit exceeded
100 Correct 945 ms 56784 KB Output is correct