답안 #854575

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854575 2023-09-28T05:51:50 Z The_Samurai Bomb (IZhO17_bomb) C++17
35 / 100
1000 ms 38608 KB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int inf = 1e9, N = 1e6 + 5;

int main() {
    cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("game.in", "r", stdin);
//    freopen("game.out", "w", stdout);
#endif

    int n, m;
    cin >> n >> m;
    vector<vector<char>> a(n + 1, vector<char>(m + 1));
    vector<vector<int>> pref(n + 1, vector<int>(m + 1));
    for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) {
        cin >> a[i][j];
        pref[i][j] = pref[i][j - 1] + pref[i - 1][j] - pref[i - 1][j - 1] + (int) (a[i][j] == '1');
    }
    auto get_sum = [&](int x1, int y1, int x2, int y2) {
        return pref[x2][y2] - pref[x2][y1 - 1] - pref[x1 - 1][y2] + pref[x1 - 1][y1 - 1];
    };
    auto check = [&](int h, int w) {
        vector<vector<bool>> vis(n + 1, vector<bool>(m + 1));
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (a[i][j] == '0') continue;
                if (i + h - 1 <= n and j + w - 1 <= m and get_sum(i, j, i + h - 1, j + w - 1) == h * w) {
                    for (int x = i; x < i + h; x++) {
                        for (int y = j; y < j + w; y++) {
                            vis[x][y] = true;
                        }
                    }
                }
                if (!vis[i][j]) return false;
            }
        }
        return true;
    };

    auto get = [&](int h) {
        int lx = 1, rx = m, best = 0;
        while (lx <= rx) {
            int mid = (lx + rx) >> 1;
            if (check(h, mid)) {
                best = mid;
                lx = mid + 1;
            } else {
                rx = mid - 1;
            }
        }
        return best;
    };
    int ans = 0, last = 0;
    for (int h = 1; h <= n; h++) {
        ans = max(ans, get(h) * h);
    }
    cout << ans;
}

Compilation message

bomb.cpp: In function 'int main()':
bomb.cpp:58:18: warning: unused variable 'last' [-Wunused-variable]
   58 |     int ans = 0, last = 0;
      |                  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 274 ms 860 KB Output is correct
4 Correct 206 ms 888 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 456 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 1 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 4 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 3 ms 348 KB Output is correct
23 Correct 11 ms 344 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 16 ms 348 KB Output is correct
26 Correct 32 ms 348 KB Output is correct
27 Correct 32 ms 860 KB Output is correct
28 Correct 24 ms 1116 KB Output is correct
29 Execution timed out 1043 ms 1116 KB Time limit exceeded
30 Execution timed out 1010 ms 1624 KB Time limit exceeded
31 Execution timed out 1065 ms 1372 KB Time limit exceeded
32 Correct 857 ms 1424 KB Output is correct
33 Execution timed out 1060 ms 1628 KB Time limit exceeded
34 Correct 64 ms 860 KB Output is correct
35 Correct 114 ms 1716 KB Output is correct
36 Execution timed out 1045 ms 1624 KB Time limit exceeded
37 Correct 1 ms 344 KB Output is correct
38 Execution timed out 1029 ms 38136 KB Time limit exceeded
39 Correct 1 ms 344 KB Output is correct
40 Execution timed out 1083 ms 5000 KB Time limit exceeded
41 Correct 1 ms 348 KB Output is correct
42 Correct 208 ms 508 KB Output is correct
43 Execution timed out 1084 ms 38384 KB Time limit exceeded
44 Execution timed out 1030 ms 1628 KB Time limit exceeded
45 Execution timed out 1035 ms 38360 KB Time limit exceeded
46 Execution timed out 1056 ms 38568 KB Time limit exceeded
47 Execution timed out 1049 ms 38228 KB Time limit exceeded
48 Execution timed out 1059 ms 38260 KB Time limit exceeded
49 Execution timed out 1006 ms 38312 KB Time limit exceeded
50 Execution timed out 1044 ms 38256 KB Time limit exceeded
51 Execution timed out 1086 ms 38332 KB Time limit exceeded
52 Execution timed out 1031 ms 38224 KB Time limit exceeded
53 Execution timed out 1061 ms 38476 KB Time limit exceeded
54 Execution timed out 1042 ms 38444 KB Time limit exceeded
55 Execution timed out 1059 ms 38480 KB Time limit exceeded
56 Execution timed out 1038 ms 38308 KB Time limit exceeded
57 Execution timed out 1032 ms 38256 KB Time limit exceeded
58 Execution timed out 1063 ms 38472 KB Time limit exceeded
59 Execution timed out 1046 ms 38216 KB Time limit exceeded
60 Execution timed out 1061 ms 38592 KB Time limit exceeded
61 Execution timed out 1063 ms 38260 KB Time limit exceeded
62 Execution timed out 1012 ms 38120 KB Time limit exceeded
63 Execution timed out 1054 ms 38228 KB Time limit exceeded
64 Execution timed out 1032 ms 38224 KB Time limit exceeded
65 Execution timed out 1057 ms 38228 KB Time limit exceeded
66 Execution timed out 1055 ms 38228 KB Time limit exceeded
67 Execution timed out 1016 ms 38260 KB Time limit exceeded
68 Execution timed out 1061 ms 38240 KB Time limit exceeded
69 Execution timed out 1012 ms 38252 KB Time limit exceeded
70 Execution timed out 1027 ms 24748 KB Time limit exceeded
71 Execution timed out 1038 ms 38372 KB Time limit exceeded
72 Execution timed out 1028 ms 38492 KB Time limit exceeded
73 Execution timed out 1049 ms 38260 KB Time limit exceeded
74 Execution timed out 1063 ms 38228 KB Time limit exceeded
75 Execution timed out 1073 ms 38252 KB Time limit exceeded
76 Execution timed out 1059 ms 38452 KB Time limit exceeded
77 Execution timed out 1020 ms 38256 KB Time limit exceeded
78 Execution timed out 1043 ms 38228 KB Time limit exceeded
79 Execution timed out 1038 ms 38596 KB Time limit exceeded
80 Execution timed out 1030 ms 38452 KB Time limit exceeded
81 Execution timed out 1025 ms 38608 KB Time limit exceeded
82 Execution timed out 1034 ms 38468 KB Time limit exceeded
83 Execution timed out 1064 ms 38472 KB Time limit exceeded
84 Execution timed out 1060 ms 38308 KB Time limit exceeded
85 Execution timed out 1065 ms 38452 KB Time limit exceeded
86 Execution timed out 1035 ms 38508 KB Time limit exceeded
87 Execution timed out 1038 ms 38432 KB Time limit exceeded
88 Execution timed out 1061 ms 38508 KB Time limit exceeded
89 Execution timed out 1040 ms 38224 KB Time limit exceeded
90 Execution timed out 1044 ms 24784 KB Time limit exceeded
91 Execution timed out 1031 ms 38256 KB Time limit exceeded
92 Execution timed out 1016 ms 38252 KB Time limit exceeded
93 Execution timed out 1095 ms 38260 KB Time limit exceeded
94 Execution timed out 1064 ms 38232 KB Time limit exceeded
95 Execution timed out 1041 ms 38256 KB Time limit exceeded
96 Execution timed out 1041 ms 38304 KB Time limit exceeded
97 Execution timed out 1039 ms 38256 KB Time limit exceeded
98 Execution timed out 1032 ms 38260 KB Time limit exceeded
99 Execution timed out 1046 ms 38224 KB Time limit exceeded
100 Execution timed out 1028 ms 38256 KB Time limit exceeded