Submission #915562

# Submission time Handle Problem Language Result Execution time Memory
915562 2024-01-24T07:17:29 Z SeDunion Bomb (IZhO17_bomb) C++17
40 / 100
1000 ms 104888 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[2505][2505], p[2505][2505];

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

    char ch[n + 5][m + 5];
    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) {
        int l = 1, r = y;
        int anss = 0;
        while(l <= r) {
            int mid = l + r >> 1;
            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 + mid <= m; j++) {
                    int c = pr[i + x][j + mid] - pr[i + x][ j ] - pr[ i ][j + mid] + pr[ i ][ j ];

                    if(c == x * mid) {
                        p[i + x + 1][j + mid + 1]++;
                        p[i + 1][j + mid + 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) {
                anss = mid;
                l = mid + 1;
            }
            else {
                r = mid - 1;
            }
        }
        y = anss;
        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:55:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |             int mid = l + r >> 1;
      |                       ~~^~~
bomb.cpp:35:9: warning: unused variable 'cnt' [-Wunused-variable]
   35 |     int cnt = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 17 ms 57948 KB Output is correct
4 Correct 19 ms 58008 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2396 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 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 2 ms 2908 KB Output is correct
20 Correct 2 ms 2908 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 2 ms 2904 KB Output is correct
23 Correct 5 ms 2908 KB Output is correct
24 Correct 2 ms 3160 KB Output is correct
25 Correct 4 ms 2908 KB Output is correct
26 Correct 4 ms 2908 KB Output is correct
27 Correct 9 ms 8540 KB Output is correct
28 Correct 20 ms 8836 KB Output is correct
29 Correct 354 ms 11356 KB Output is correct
30 Correct 147 ms 14172 KB Output is correct
31 Correct 133 ms 11388 KB Output is correct
32 Correct 110 ms 11612 KB Output is correct
33 Correct 225 ms 14376 KB Output is correct
34 Correct 19 ms 10844 KB Output is correct
35 Correct 55 ms 14172 KB Output is correct
36 Correct 305 ms 14372 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Execution timed out 1072 ms 104636 KB Time limit exceeded
39 Correct 1 ms 2396 KB Output is correct
40 Execution timed out 1076 ms 32860 KB Time limit exceeded
41 Correct 1 ms 2396 KB Output is correct
42 Correct 12 ms 2904 KB Output is correct
43 Execution timed out 1073 ms 104532 KB Time limit exceeded
44 Execution timed out 1012 ms 14168 KB Time limit exceeded
45 Execution timed out 1079 ms 104636 KB Time limit exceeded
46 Execution timed out 1051 ms 104636 KB Time limit exceeded
47 Execution timed out 1036 ms 104636 KB Time limit exceeded
48 Execution timed out 1022 ms 104648 KB Time limit exceeded
49 Execution timed out 1034 ms 104636 KB Time limit exceeded
50 Execution timed out 1065 ms 104636 KB Time limit exceeded
51 Execution timed out 1058 ms 104408 KB Time limit exceeded
52 Execution timed out 1064 ms 104784 KB Time limit exceeded
53 Execution timed out 1069 ms 104460 KB Time limit exceeded
54 Execution timed out 1093 ms 104528 KB Time limit exceeded
55 Execution timed out 1059 ms 104388 KB Time limit exceeded
56 Execution timed out 1064 ms 104640 KB Time limit exceeded
57 Execution timed out 1016 ms 104528 KB Time limit exceeded
58 Execution timed out 1059 ms 104380 KB Time limit exceeded
59 Execution timed out 1040 ms 104532 KB Time limit exceeded
60 Execution timed out 1058 ms 104628 KB Time limit exceeded
61 Execution timed out 1060 ms 104536 KB Time limit exceeded
62 Execution timed out 1064 ms 104636 KB Time limit exceeded
63 Execution timed out 1040 ms 104532 KB Time limit exceeded
64 Execution timed out 1025 ms 104532 KB Time limit exceeded
65 Execution timed out 1063 ms 104640 KB Time limit exceeded
66 Execution timed out 1026 ms 104528 KB Time limit exceeded
67 Execution timed out 1040 ms 104648 KB Time limit exceeded
68 Execution timed out 1008 ms 104648 KB Time limit exceeded
69 Execution timed out 1047 ms 104620 KB Time limit exceeded
70 Execution timed out 1054 ms 84820 KB Time limit exceeded
71 Execution timed out 1016 ms 104532 KB Time limit exceeded
72 Execution timed out 1049 ms 104532 KB Time limit exceeded
73 Execution timed out 1069 ms 104384 KB Time limit exceeded
74 Execution timed out 1018 ms 104420 KB Time limit exceeded
75 Execution timed out 1042 ms 104380 KB Time limit exceeded
76 Execution timed out 1027 ms 104532 KB Time limit exceeded
77 Execution timed out 1057 ms 104384 KB Time limit exceeded
78 Execution timed out 1034 ms 104528 KB Time limit exceeded
79 Execution timed out 1043 ms 104624 KB Time limit exceeded
80 Execution timed out 1040 ms 104532 KB Time limit exceeded
81 Execution timed out 1064 ms 104532 KB Time limit exceeded
82 Execution timed out 1042 ms 104528 KB Time limit exceeded
83 Execution timed out 1054 ms 104532 KB Time limit exceeded
84 Execution timed out 1053 ms 104632 KB Time limit exceeded
85 Execution timed out 1056 ms 104484 KB Time limit exceeded
86 Execution timed out 1054 ms 104636 KB Time limit exceeded
87 Execution timed out 1043 ms 104528 KB Time limit exceeded
88 Execution timed out 1065 ms 104380 KB Time limit exceeded
89 Execution timed out 1105 ms 104480 KB Time limit exceeded
90 Execution timed out 1037 ms 84816 KB Time limit exceeded
91 Execution timed out 1045 ms 104492 KB Time limit exceeded
92 Execution timed out 1043 ms 104888 KB Time limit exceeded
93 Execution timed out 1053 ms 104532 KB Time limit exceeded
94 Execution timed out 1039 ms 104644 KB Time limit exceeded
95 Execution timed out 1027 ms 104628 KB Time limit exceeded
96 Execution timed out 1057 ms 104624 KB Time limit exceeded
97 Execution timed out 1070 ms 104620 KB Time limit exceeded
98 Execution timed out 1051 ms 104532 KB Time limit exceeded
99 Execution timed out 1066 ms 104532 KB Time limit exceeded
100 Execution timed out 1051 ms 104624 KB Time limit exceeded