답안 #706368

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
706368 2023-03-06T10:51:31 Z nifeshe Bomb (IZhO17_bomb) C++17
39 / 100
1000 ms 84196 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma comment (linker, "/STACK: 16777216")

#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
//#define int long long

using namespace std;
using namespace __gnu_pbds;

template <typename T> inline bool umax(T &a, const T &b) { if(a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool umin(T &a, const T &b) { if(a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> using oset = tree<T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int mod = 998244353;
const ll base = 1e6 + 5;
const ll inf = 1e18;
const int MAX = 3e3 + 1;
const int LG = 20;

random_device rd;
mt19937 gen(rd());
uniform_int_distribution<ll> dis(1, inf);

int n, m;
int pref[MAX][MAX];
int a[MAX][MAX];

int get(int x1, int y1, int x2, int y2) {
    int ans = pref[x2][y2] - (x1? pref[x1 - 1][y2] : 0) - (y1? pref[x2][y1 - 1] : 0) + (x1 && y1? pref[x1 - 1][y1 - 1] : 0);
    return ans;
}

bool bad (int s, int t) {
    vector <vector <int>> f (n + 1, vector <int> (m + 1));
    for (int i = 0; i + s - 1 < n; ++i) {
        for (int j = 0; j + t - 1 < m; ++j) {
            if (!get(i, j, i + s - 1, j + t - 1)) {
                ++f[i][j];
                --f[i + s][j];
                --f[i][j + t];
                ++f[i + s][j + t];
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (i) f[i][j] += f[i - 1][j];
            if (j) f[i][j] += f[i][j - 1];
            if (i && j) f[i][j] -= f[i - 1][j - 1];
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (a[i][j] && !f[i][j]) return 1;
        }
    }
    return 0;
}

void solve() {
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            char c;
            cin >> c;
            a[i][j] = c - '0';
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            pref[i][j] = a[i][j] ^ 1;
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if (i) pref[i][j] += pref[i - 1][j];
            if (j) pref[i][j] += pref[i][j - 1];
            if (i && j) pref[i][j] -= pref[i - 1][j - 1];
        }
    }
    int l = 1, r = min(m, n);
    int x = -1;
    while(l <= r) {
        int mid = (l + r) / 2;
        if(!bad(mid, mid)) {
            l = mid + 1;
            x = mid;
        }
        else r = mid - 1;
    }
    ll ans = 0;
    int lst;
    l = x, r = n;
    lst = -1;
    while(l <= r) {
        int mid = (l + r) / 2;
        if(!bad(mid, x)) {
            l = mid + 1;
            lst = mid;
        }
        else r = mid - 1;
    }
    umax(ans, 1LL * x * lst);
    l = x, r = m;
    lst = -1;
    while(l <= r) {
        int mid = (l + r) / 2;
        if(!bad(x, mid)) {
            l = mid + 1;
            lst = mid;
        }
        else r = mid - 1;
    }
    umax(ans, 1LL * x * lst);
    cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int ttt = 1;
//    cin >> ttt;
    while(ttt--) {
        solve();
    }
    return 0;
}

Compilation message

bomb.cpp:8: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    8 | #pragma comment (linker, "/STACK: 16777216")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 10 ms 20564 KB Output is correct
4 Correct 9 ms 20536 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 2 ms 1160 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 2 ms 1236 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 3 ms 1236 KB Output is correct
26 Correct 2 ms 1204 KB Output is correct
27 Correct 17 ms 3652 KB Output is correct
28 Correct 17 ms 4032 KB Output is correct
29 Incorrect 23 ms 4948 KB Output isn't correct
30 Correct 34 ms 6084 KB Output is correct
31 Correct 24 ms 4756 KB Output is correct
32 Correct 25 ms 5492 KB Output is correct
33 Correct 37 ms 6368 KB Output is correct
34 Correct 12 ms 4188 KB Output is correct
35 Correct 35 ms 6396 KB Output is correct
36 Correct 42 ms 6324 KB Output is correct
37 Incorrect 1 ms 468 KB Output isn't correct
38 Correct 580 ms 83744 KB Output is correct
39 Correct 0 ms 468 KB Output is correct
40 Incorrect 151 ms 16496 KB Output isn't correct
41 Incorrect 1 ms 468 KB Output isn't correct
42 Incorrect 2 ms 1236 KB Output isn't correct
43 Execution timed out 1089 ms 83836 KB Time limit exceeded
44 Incorrect 32 ms 6400 KB Output isn't correct
45 Execution timed out 1086 ms 83772 KB Time limit exceeded
46 Execution timed out 1079 ms 83824 KB Time limit exceeded
47 Execution timed out 1087 ms 83672 KB Time limit exceeded
48 Execution timed out 1064 ms 83720 KB Time limit exceeded
49 Execution timed out 1085 ms 84004 KB Time limit exceeded
50 Execution timed out 1086 ms 83796 KB Time limit exceeded
51 Execution timed out 1092 ms 83736 KB Time limit exceeded
52 Execution timed out 1084 ms 84000 KB Time limit exceeded
53 Execution timed out 1090 ms 83680 KB Time limit exceeded
54 Execution timed out 1081 ms 83716 KB Time limit exceeded
55 Execution timed out 1094 ms 83820 KB Time limit exceeded
56 Execution timed out 1081 ms 83784 KB Time limit exceeded
57 Execution timed out 1087 ms 83800 KB Time limit exceeded
58 Execution timed out 1086 ms 83672 KB Time limit exceeded
59 Execution timed out 1061 ms 83840 KB Time limit exceeded
60 Execution timed out 1085 ms 83760 KB Time limit exceeded
61 Execution timed out 1086 ms 83972 KB Time limit exceeded
62 Execution timed out 1089 ms 83844 KB Time limit exceeded
63 Execution timed out 1080 ms 83868 KB Time limit exceeded
64 Execution timed out 1058 ms 83656 KB Time limit exceeded
65 Execution timed out 1093 ms 83796 KB Time limit exceeded
66 Execution timed out 1086 ms 83960 KB Time limit exceeded
67 Execution timed out 1085 ms 83808 KB Time limit exceeded
68 Execution timed out 1092 ms 83820 KB Time limit exceeded
69 Execution timed out 1090 ms 83776 KB Time limit exceeded
70 Correct 847 ms 63216 KB Output is correct
71 Execution timed out 1082 ms 83756 KB Time limit exceeded
72 Execution timed out 1081 ms 83760 KB Time limit exceeded
73 Execution timed out 1087 ms 83988 KB Time limit exceeded
74 Execution timed out 1088 ms 83780 KB Time limit exceeded
75 Execution timed out 1072 ms 84196 KB Time limit exceeded
76 Execution timed out 1080 ms 83848 KB Time limit exceeded
77 Execution timed out 1087 ms 83944 KB Time limit exceeded
78 Execution timed out 1035 ms 83660 KB Time limit exceeded
79 Execution timed out 1094 ms 83752 KB Time limit exceeded
80 Execution timed out 1081 ms 83768 KB Time limit exceeded
81 Execution timed out 1089 ms 83716 KB Time limit exceeded
82 Execution timed out 1084 ms 83788 KB Time limit exceeded
83 Execution timed out 1085 ms 83884 KB Time limit exceeded
84 Execution timed out 1089 ms 83836 KB Time limit exceeded
85 Execution timed out 1057 ms 83896 KB Time limit exceeded
86 Execution timed out 1083 ms 83836 KB Time limit exceeded
87 Execution timed out 1066 ms 83848 KB Time limit exceeded
88 Execution timed out 1086 ms 83796 KB Time limit exceeded
89 Execution timed out 1085 ms 83892 KB Time limit exceeded
90 Correct 872 ms 63352 KB Output is correct
91 Execution timed out 1086 ms 83876 KB Time limit exceeded
92 Execution timed out 1087 ms 83720 KB Time limit exceeded
93 Execution timed out 1082 ms 84016 KB Time limit exceeded
94 Execution timed out 1093 ms 83804 KB Time limit exceeded
95 Execution timed out 1090 ms 83820 KB Time limit exceeded
96 Execution timed out 1041 ms 83724 KB Time limit exceeded
97 Execution timed out 1081 ms 83784 KB Time limit exceeded
98 Execution timed out 1086 ms 83932 KB Time limit exceeded
99 Execution timed out 1085 ms 83672 KB Time limit exceeded
100 Execution timed out 1080 ms 83920 KB Time limit exceeded