Submission #452098

# Submission time Handle Problem Language Result Execution time Memory
452098 2021-08-03T19:06:42 Z dxz05 Bomb (IZhO17_bomb) C++14
10 / 100
1000 ms 59948 KB
#pragma GCC optimize("Ofast,O2,O3")
#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << "[" << H << "]";
    debug_out(T...);
}

#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define revall(x) (x).rbegin(), (x).rend()

clock_t startTime;

double getCurrentTime() {
    return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}

#define MP make_pair

typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.00001;
const int MOD = 1e9;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 2e6 + 3e2;
const int M = 2522;

int n, m;
int a[M][M];
bool bomb[M][M];
int dp[M][M];

int sum(int x1, int y1, int x2, int y2){
    assert(x1 <= x2 && y1 <= y2);
    int res = dp[x2][y2];
    res -= dp[x1 - 1][y2];
    res -= dp[x2][y1 - 1];
    res += dp[x1 - 1][y1 - 1];
    return res;
}

bool check(int A, int B){
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++) bomb[i][j] = false;
    }

    for (int i = 1; i <= n - A + 1; i++){
        for (int j = 1; j <= m - B + 1; j++){
            if (bomb[i][j] || !a[i][j]) continue;
            if (sum(i, j, i + A - 1, j + B - 1) == A * B){
                for (int x = i; x <= i + A - 1; x++){
                    for (int y = j; y <= j + B - 1; y++){
                        bomb[x][y] = true;
                    }
                }
            }
        }
    }

    for (int i = n; i >= A; i--){
        for (int j = m; j >= B; j--){
            if (bomb[i][j] || !a[i][j]) continue;
            if (sum(i - A + 1, j - B + 1, i, j) == A * B){
                for (int x = i - A + 1; x <= i; x++){
                    for (int y = j - B + 1; y <= j; y++){
                        bomb[x][y] = true;
                    }
                }
            }
        }
    }

    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            if (!bomb[i][j] && a[i][j]) return false;
        }
    }

    return true;
}

void solve(int TC) {
    cin >> n >> m;

    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            char ch;
            cin >> ch;
            a[i][j] = ch - '0';
            dp[i][j] = dp[i][j - 1] + a[i][j];
        }
    }

    for (int j = 1; j <= m; j++){
        for (int i = 1; i <= n; i++){
            dp[i][j] += dp[i - 1][j];
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            if (check(i, j)) ans = max(ans, i * j);
        }
    }

    cout << ans;

}

int main() {
    startTime = clock();
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    bool llololcal = false;
#ifdef dddxxz
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    llololcal = true;
#endif

    int TC = 1;
    //cin >> TC;

    for (int test = 1; test <= TC; test++) {
        debug(test);
        //cout << "Case #" << test << ": ";
        solve(test);
    }

    if (llololcal) cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;

    return 0;
}

Compilation message

bomb.cpp: In function 'int main()':
bomb.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
bomb.cpp:143:9: note: in expansion of macro 'debug'
  143 |         debug(test);
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 187 ms 26552 KB Output is correct
4 Correct 210 ms 26572 KB Output is correct
5 Correct 16 ms 332 KB Output is correct
6 Correct 3 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Incorrect 1 ms 460 KB Output isn't correct
9 Incorrect 1 ms 460 KB Output isn't correct
10 Incorrect 1 ms 460 KB Output isn't correct
11 Incorrect 1 ms 460 KB Output isn't correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Incorrect 1 ms 460 KB Output isn't correct
16 Incorrect 1 ms 460 KB Output isn't correct
17 Incorrect 43 ms 972 KB Output isn't correct
18 Incorrect 24 ms 1076 KB Output isn't correct
19 Incorrect 68 ms 1360 KB Output isn't correct
20 Incorrect 74 ms 1336 KB Output isn't correct
21 Incorrect 22 ms 844 KB Output isn't correct
22 Incorrect 56 ms 1164 KB Output isn't correct
23 Incorrect 114 ms 1440 KB Output isn't correct
24 Incorrect 49 ms 1208 KB Output isn't correct
25 Incorrect 132 ms 1440 KB Output isn't correct
26 Incorrect 150 ms 1440 KB Output isn't correct
27 Execution timed out 1091 ms 4044 KB Time limit exceeded
28 Execution timed out 1070 ms 4300 KB Time limit exceeded
29 Execution timed out 1082 ms 5452 KB Time limit exceeded
30 Execution timed out 1086 ms 6348 KB Time limit exceeded
31 Execution timed out 1093 ms 5068 KB Time limit exceeded
32 Execution timed out 1099 ms 5836 KB Time limit exceeded
33 Execution timed out 1089 ms 6732 KB Time limit exceeded
34 Execution timed out 1086 ms 4684 KB Time limit exceeded
35 Execution timed out 1094 ms 6732 KB Time limit exceeded
36 Execution timed out 1083 ms 6732 KB Time limit exceeded
37 Incorrect 1 ms 460 KB Output isn't correct
38 Execution timed out 1091 ms 59752 KB Time limit exceeded
39 Incorrect 1 ms 460 KB Output isn't correct
40 Execution timed out 1094 ms 16204 KB Time limit exceeded
41 Incorrect 1 ms 460 KB Output isn't correct
42 Incorrect 133 ms 1356 KB Output isn't correct
43 Execution timed out 1092 ms 59812 KB Time limit exceeded
44 Execution timed out 1094 ms 6732 KB Time limit exceeded
45 Execution timed out 1092 ms 59844 KB Time limit exceeded
46 Execution timed out 1088 ms 59748 KB Time limit exceeded
47 Execution timed out 1094 ms 59724 KB Time limit exceeded
48 Execution timed out 1083 ms 59828 KB Time limit exceeded
49 Execution timed out 1094 ms 59716 KB Time limit exceeded
50 Execution timed out 1050 ms 59824 KB Time limit exceeded
51 Execution timed out 1084 ms 59768 KB Time limit exceeded
52 Execution timed out 1090 ms 59776 KB Time limit exceeded
53 Execution timed out 1065 ms 59812 KB Time limit exceeded
54 Execution timed out 1087 ms 59716 KB Time limit exceeded
55 Execution timed out 1092 ms 59748 KB Time limit exceeded
56 Execution timed out 1090 ms 59724 KB Time limit exceeded
57 Execution timed out 1082 ms 59716 KB Time limit exceeded
58 Execution timed out 1100 ms 59716 KB Time limit exceeded
59 Execution timed out 1097 ms 59716 KB Time limit exceeded
60 Execution timed out 1083 ms 59948 KB Time limit exceeded
61 Execution timed out 1092 ms 59728 KB Time limit exceeded
62 Execution timed out 1091 ms 59712 KB Time limit exceeded
63 Execution timed out 1039 ms 59828 KB Time limit exceeded
64 Execution timed out 1088 ms 59716 KB Time limit exceeded
65 Execution timed out 1047 ms 59716 KB Time limit exceeded
66 Execution timed out 1082 ms 59764 KB Time limit exceeded
67 Execution timed out 1096 ms 59716 KB Time limit exceeded
68 Execution timed out 1090 ms 59716 KB Time limit exceeded
69 Execution timed out 1087 ms 59656 KB Time limit exceeded
70 Execution timed out 1088 ms 48580 KB Time limit exceeded
71 Execution timed out 1090 ms 59588 KB Time limit exceeded
72 Execution timed out 1080 ms 59592 KB Time limit exceeded
73 Execution timed out 1084 ms 59580 KB Time limit exceeded
74 Execution timed out 1087 ms 59580 KB Time limit exceeded
75 Execution timed out 1095 ms 59684 KB Time limit exceeded
76 Execution timed out 1065 ms 59656 KB Time limit exceeded
77 Execution timed out 1087 ms 59676 KB Time limit exceeded
78 Execution timed out 1094 ms 59596 KB Time limit exceeded
79 Execution timed out 1096 ms 59616 KB Time limit exceeded
80 Execution timed out 1089 ms 59552 KB Time limit exceeded
81 Execution timed out 1076 ms 59516 KB Time limit exceeded
82 Execution timed out 1087 ms 59704 KB Time limit exceeded
83 Execution timed out 1091 ms 59556 KB Time limit exceeded
84 Execution timed out 1079 ms 59556 KB Time limit exceeded
85 Execution timed out 1078 ms 59600 KB Time limit exceeded
86 Execution timed out 1082 ms 59536 KB Time limit exceeded
87 Execution timed out 1089 ms 59492 KB Time limit exceeded
88 Execution timed out 1089 ms 59584 KB Time limit exceeded
89 Execution timed out 1090 ms 59556 KB Time limit exceeded
90 Execution timed out 1090 ms 48324 KB Time limit exceeded
91 Execution timed out 1093 ms 59508 KB Time limit exceeded
92 Execution timed out 1082 ms 59588 KB Time limit exceeded
93 Execution timed out 1089 ms 59460 KB Time limit exceeded
94 Execution timed out 1087 ms 59460 KB Time limit exceeded
95 Execution timed out 1088 ms 59524 KB Time limit exceeded
96 Execution timed out 1087 ms 59460 KB Time limit exceeded
97 Execution timed out 1099 ms 59520 KB Time limit exceeded
98 Execution timed out 1082 ms 59588 KB Time limit exceeded
99 Execution timed out 1093 ms 59460 KB Time limit exceeded
100 Execution timed out 1090 ms 59404 KB Time limit exceeded