Submission #915554

# Submission time Handle Problem Language Result Execution time Memory
915554 2024-01-24T07:06:47 Z vjudge1 Bomb (IZhO17_bomb) C++17
41 / 100
1000 ms 108652 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

#include <bits/stdc++.h>
 
#define int long long 
#define pb push_back
#define ui unsigned int
#define ld long double
#define pl pair<long long int,  long long int>
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first    
#define ss second
#define sz size()
#define all(x) x.begin(), x.end()
 
using namespace std;
 
const int maxn = 1e6 + 11;
const int inf = 1e17 + 1;
const int mod = 1e9 + 7;
// const int mod = 998244353;
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1 , 0, -1, 1, -1, 1};
const double eps = 1e-10;

int n, m;

int pr[2501][2501], p[2501][2501];

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

    char ch[n + 1][m + 1];
    int cnt = 0;

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> ch[ i ][ j ];
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            pr[ i ][ j ] = pr[i - 1][ j ] + pr[ i ][j - 1] - pr[i - 1][j - 1] + (ch[ i ][ j ] - '0');
        }
    }
    int y = m;
    int x = 1;
    int ans = 0;

    while(x <= n && y) {
        while(y) {
            for(int i = 0; i <= n; i++) {
                for(int j = 0; j <= m; j++) {
                    p[ i ][ j ] = 0;
                }
            }
            for(int i = 0; i + x <= n; i++) {
                for(int j = 0; j + y <= m; j++) {
                    int c = pr[i + x][j + y] - pr[i + x][ j ] - pr[ i ][j + y] + pr[ i ][ j ];

                    if(c == x * y) {
                        p[i + x + 1][j + y + 1]++;
                        p[i + 1][j + y + 1]--;
                        p[i + x + 1][j + 1]--;
                        p[i + 1][j + 1]++;
                    }
                }
            }

            for(int i = 1; i <= n; i++) {
                for(int j = 1; j <= m; j++) {
                    p[ i ][ j ] += p[i - 1][ j ] + p[ i ][j - 1] - p[i - 1][j - 1];
                }
            }
            bool fl = true;
            for(int i = 1; i <= n; i++) {
                for(int j = 1; j <= m; j++) {
                    if(ch[ i ][ j ] == '1' && p[ i ][ j ] == 0) {
                        fl = false;
                        break;
                    }
                }
            }
            if(fl) {
                break;
            }
            y--;
        }
        ans = max(ans, x * y);
        x++;
    }
    cout << ans;
}
    
signed main() {
    // freopen("sum.in", "r", stdin); 
    // freopen("sum.out", "w", stdout);
 
    boost;      

    int tt = 1;

    // cin >> tt;

    for(int i = 1; i <= tt; i++) {
        // cout << "Case " << i << ":\n";
        solve();    
    }           
}

Compilation message

bomb.cpp: In function 'void solve()':
bomb.cpp:35:9: warning: unused variable 'cnt' [-Wunused-variable]
   35 |     int cnt = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 16 ms 57980 KB Output is correct
4 Correct 15 ms 57948 KB Output is correct
5 Correct 11 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2520 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2908 KB Output is correct
20 Correct 2 ms 2908 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 3 ms 2904 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 5 ms 3052 KB Output is correct
26 Correct 5 ms 2908 KB Output is correct
27 Correct 66 ms 8540 KB Output is correct
28 Correct 81 ms 8900 KB Output is correct
29 Correct 146 ms 11356 KB Output is correct
30 Correct 193 ms 15676 KB Output is correct
31 Correct 149 ms 11352 KB Output is correct
32 Correct 144 ms 12116 KB Output is correct
33 Correct 233 ms 15812 KB Output is correct
34 Correct 38 ms 10844 KB Output is correct
35 Correct 177 ms 15812 KB Output is correct
36 Correct 342 ms 15816 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Execution timed out 1031 ms 108544 KB Time limit exceeded
39 Correct 1 ms 2396 KB Output is correct
40 Execution timed out 1051 ms 33700 KB Time limit exceeded
41 Correct 1 ms 2396 KB Output is correct
42 Correct 4 ms 3056 KB Output is correct
43 Execution timed out 1047 ms 108492 KB Time limit exceeded
44 Correct 300 ms 15708 KB Output is correct
45 Execution timed out 1094 ms 108608 KB Time limit exceeded
46 Execution timed out 1020 ms 108440 KB Time limit exceeded
47 Execution timed out 1027 ms 108376 KB Time limit exceeded
48 Execution timed out 1033 ms 108372 KB Time limit exceeded
49 Execution timed out 1079 ms 108376 KB Time limit exceeded
50 Execution timed out 1097 ms 108368 KB Time limit exceeded
51 Execution timed out 1008 ms 108536 KB Time limit exceeded
52 Execution timed out 1024 ms 108492 KB Time limit exceeded
53 Execution timed out 1089 ms 108368 KB Time limit exceeded
54 Execution timed out 1026 ms 108372 KB Time limit exceeded
55 Execution timed out 1087 ms 108368 KB Time limit exceeded
56 Execution timed out 1032 ms 108432 KB Time limit exceeded
57 Execution timed out 1040 ms 108452 KB Time limit exceeded
58 Execution timed out 1020 ms 108368 KB Time limit exceeded
59 Execution timed out 1081 ms 108300 KB Time limit exceeded
60 Execution timed out 1016 ms 108544 KB Time limit exceeded
61 Execution timed out 1030 ms 108416 KB Time limit exceeded
62 Execution timed out 1072 ms 108428 KB Time limit exceeded
63 Execution timed out 1025 ms 108540 KB Time limit exceeded
64 Execution timed out 1082 ms 108368 KB Time limit exceeded
65 Execution timed out 1053 ms 108368 KB Time limit exceeded
66 Execution timed out 1048 ms 108324 KB Time limit exceeded
67 Execution timed out 1092 ms 108368 KB Time limit exceeded
68 Execution timed out 1057 ms 108460 KB Time limit exceeded
69 Execution timed out 1072 ms 108368 KB Time limit exceeded
70 Execution timed out 1026 ms 87892 KB Time limit exceeded
71 Execution timed out 1100 ms 108372 KB Time limit exceeded
72 Execution timed out 1067 ms 108432 KB Time limit exceeded
73 Execution timed out 1050 ms 108548 KB Time limit exceeded
74 Execution timed out 1085 ms 108332 KB Time limit exceeded
75 Execution timed out 1036 ms 108408 KB Time limit exceeded
76 Execution timed out 1081 ms 108412 KB Time limit exceeded
77 Execution timed out 1088 ms 108452 KB Time limit exceeded
78 Execution timed out 1014 ms 108352 KB Time limit exceeded
79 Execution timed out 1037 ms 108368 KB Time limit exceeded
80 Execution timed out 1020 ms 108484 KB Time limit exceeded
81 Execution timed out 1028 ms 108472 KB Time limit exceeded
82 Execution timed out 1081 ms 108360 KB Time limit exceeded
83 Execution timed out 1046 ms 108372 KB Time limit exceeded
84 Execution timed out 1020 ms 108348 KB Time limit exceeded
85 Execution timed out 1014 ms 108304 KB Time limit exceeded
86 Execution timed out 1018 ms 108372 KB Time limit exceeded
87 Execution timed out 1016 ms 108316 KB Time limit exceeded
88 Execution timed out 1056 ms 108392 KB Time limit exceeded
89 Execution timed out 1038 ms 108652 KB Time limit exceeded
90 Execution timed out 1103 ms 87892 KB Time limit exceeded
91 Execution timed out 1078 ms 108404 KB Time limit exceeded
92 Execution timed out 1029 ms 108372 KB Time limit exceeded
93 Execution timed out 1016 ms 108372 KB Time limit exceeded
94 Execution timed out 1008 ms 108476 KB Time limit exceeded
95 Execution timed out 1024 ms 108432 KB Time limit exceeded
96 Execution timed out 1077 ms 108516 KB Time limit exceeded
97 Execution timed out 1027 ms 108372 KB Time limit exceeded
98 Execution timed out 1035 ms 108368 KB Time limit exceeded
99 Execution timed out 1098 ms 108372 KB Time limit exceeded
100 Execution timed out 1060 ms 107860 KB Time limit exceeded