Submission #855504

# Submission time Handle Problem Language Result Execution time Memory
855504 2023-10-01T11:20:35 Z Alfraganus Bomb (IZhO17_bomb) C++17
9 / 100
1000 ms 67824 KB
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
#define fs first
#define ss second
#define all(a) a.begin(), a.end()
#define print(a)          \
    for (auto x : a)      \
        cout << x << ' '; \
    cout << endl;

#define printmp(a)   \
    for (auto x : a) \
        cout << x.fs << ' ' << x.ss << endl;

vector<vector<char>> a;
int n, m;

bool check(int y){
    for(int j = 0; j < m; j ++){
        int cnt = 0;
        for(int i = 0; i < n; i ++){
            if(a[i][j] == '0')
                if(cnt > 0 and cnt < y)
                    return false;
                else
                    cnt = 0;
            else
                cnt ++;
        }
        if(cnt > 0 and cnt < y)
            return false;
    }
    return true;
}

bool good(int y)
{
    for (int j = 0; j < n; j++)
    {
        int cnt = 0;
        for (int i = 0; i < m; i++)
        {
            if (a[j][i] == '0')
                if (cnt > 0 and cnt < y)
                    return false;
                else
                    cnt = 0;
            else
                cnt++;
        }
        if (cnt > 0 and cnt < y)
            return false;
    }
    return true;
}

int SUM(vector<vector<int>> &sum, int i, int j, int x, int y){
    return sum[i][j] - (i - x < 0 ? 0 : sum[i - x][j]) - (j - y < 0 ? 0 : sum[i][j - y]) + (i - x < 0 or j - y < 0 ? 0 : sum[i - x][j - y]);
}

bool f1(int x, int y){
    vector<vector<char>> b = a;
    vector<vector<int>> sum(n, vector<int> (m));
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < m; j ++){
            if(b[i][j] == '1'){
                sum[i][j] = 1;
            }
        }
    }
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < m; j ++){
            sum[i][j] += (i == 0 ? 0 : sum[i - 1][j]) + (j == 0 ? 0 : sum[i][j - 1]) - (i == 0 or j == 0 ? 0 : sum[i - 1][j - 1]);
        }
    }
    for(int i = x - 1; i < n; i ++){
        for(int j = y - 1; j < m; j ++){
            if(SUM(sum, i, j, x, y) == x * y){
                for(int k = 0; k < x; k ++){
                    for(int t = 0; t < y; t ++){
                        if(b[i - k][j - t] == '1'){
                            b[i - k][j - t] = '2';
                        }
                        else{
                            break;
                        }
                    }
                }
            }
        }
    }
    int cnt = 0;
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < m; j ++){
            cnt += b[i][j] = '1';
        }
    }
    return cnt == 0;
}

void solve(){
    cin >> n >> m;
    a.resize(n, vector<char> (m));
    for(int i = 0; i < n; i ++)
        for(int j = 0; j < m; j ++)
            cin >> a[i][j];
    int lx = 1, rx = n;
    while(lx < rx){
        int m = (lx + rx + 1) >> 1;
        if(check(m))
            lx = m;
        else
            rx = m - 1;
    }
    int ly = 1, ry = m;
    while(ly < ry){
        int m = (ly + ry + 1) >> 1;
        if(good(m))
            ly = m;
        else
            ry = m - 1;
    }
    int LX = 1, RX = n;
    while(LX < RX){
        int m = (LX + RX + 1) >> 1;
        if(f1(lx, m))
            LX = m;
        else
            RX = m - 1;
    }
    int LY = 1, RY = n;
    while (LY < RY)
    {
        int m = (LY + RY + 1) >> 1;
        if (f1(m, ly))
            LY = m;
        else
            RY = m - 1;
    }
    cout << max(lx * LX, ly * LY);
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    // freopen("bomb.in", "r", stdin);
    // freopen("bomb.out", "w", stdout);
    int t = 1;
    // cin >> t;
    while(t --){
        solve();
        cout << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 7 ms 716 KB Output is correct
4 Correct 6 ms 860 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Incorrect 0 ms 460 KB Output isn't correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 Incorrect 0 ms 348 KB Output isn't correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Incorrect 0 ms 348 KB Output isn't correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Incorrect 1 ms 348 KB Output isn't correct
18 Incorrect 1 ms 348 KB Output isn't correct
19 Incorrect 1 ms 348 KB Output isn't correct
20 Incorrect 1 ms 348 KB Output isn't correct
21 Incorrect 1 ms 348 KB Output isn't correct
22 Incorrect 1 ms 348 KB Output isn't correct
23 Incorrect 1 ms 348 KB Output isn't correct
24 Incorrect 1 ms 348 KB Output isn't correct
25 Incorrect 1 ms 348 KB Output isn't correct
26 Incorrect 2 ms 348 KB Output isn't correct
27 Correct 22 ms 1348 KB Output is correct
28 Incorrect 17 ms 1736 KB Output isn't correct
29 Incorrect 75 ms 1856 KB Output isn't correct
30 Incorrect 31 ms 2544 KB Output isn't correct
31 Incorrect 22 ms 2100 KB Output isn't correct
32 Incorrect 24 ms 2172 KB Output isn't correct
33 Incorrect 35 ms 2664 KB Output isn't correct
34 Incorrect 12 ms 1372 KB Output isn't correct
35 Incorrect 41 ms 2704 KB Output isn't correct
36 Incorrect 140 ms 2896 KB Output isn't correct
37 Incorrect 0 ms 448 KB Output isn't correct
38 Execution timed out 1061 ms 67620 KB Time limit exceeded
39 Incorrect 1 ms 344 KB Output isn't correct
40 Incorrect 679 ms 8844 KB Output isn't correct
41 Incorrect 0 ms 348 KB Output isn't correct
42 Incorrect 2 ms 512 KB Output isn't correct
43 Execution timed out 1065 ms 67544 KB Time limit exceeded
44 Incorrect 61 ms 2668 KB Output isn't correct
45 Execution timed out 1035 ms 67572 KB Time limit exceeded
46 Execution timed out 1024 ms 67728 KB Time limit exceeded
47 Execution timed out 1014 ms 67592 KB Time limit exceeded
48 Execution timed out 1050 ms 67612 KB Time limit exceeded
49 Execution timed out 1048 ms 67804 KB Time limit exceeded
50 Execution timed out 1051 ms 67544 KB Time limit exceeded
51 Execution timed out 1028 ms 67548 KB Time limit exceeded
52 Execution timed out 1008 ms 67644 KB Time limit exceeded
53 Execution timed out 1049 ms 67572 KB Time limit exceeded
54 Execution timed out 1091 ms 67544 KB Time limit exceeded
55 Execution timed out 1050 ms 67772 KB Time limit exceeded
56 Execution timed out 1060 ms 67696 KB Time limit exceeded
57 Execution timed out 1096 ms 67612 KB Time limit exceeded
58 Execution timed out 1030 ms 67800 KB Time limit exceeded
59 Execution timed out 1053 ms 67628 KB Time limit exceeded
60 Execution timed out 1027 ms 67556 KB Time limit exceeded
61 Execution timed out 1049 ms 67792 KB Time limit exceeded
62 Execution timed out 1043 ms 67612 KB Time limit exceeded
63 Execution timed out 1022 ms 67600 KB Time limit exceeded
64 Execution timed out 1048 ms 67592 KB Time limit exceeded
65 Execution timed out 1065 ms 67592 KB Time limit exceeded
66 Execution timed out 1081 ms 67652 KB Time limit exceeded
67 Execution timed out 1035 ms 67544 KB Time limit exceeded
68 Execution timed out 1006 ms 67492 KB Time limit exceeded
69 Execution timed out 1031 ms 67776 KB Time limit exceeded
70 Incorrect 978 ms 43872 KB Output isn't correct
71 Execution timed out 1046 ms 67720 KB Time limit exceeded
72 Execution timed out 1075 ms 67652 KB Time limit exceeded
73 Execution timed out 1022 ms 67548 KB Time limit exceeded
74 Execution timed out 1014 ms 67620 KB Time limit exceeded
75 Execution timed out 1048 ms 67592 KB Time limit exceeded
76 Execution timed out 1045 ms 67736 KB Time limit exceeded
77 Execution timed out 1089 ms 67692 KB Time limit exceeded
78 Execution timed out 1004 ms 67632 KB Time limit exceeded
79 Execution timed out 1004 ms 67716 KB Time limit exceeded
80 Execution timed out 1054 ms 67604 KB Time limit exceeded
81 Execution timed out 1008 ms 67680 KB Time limit exceeded
82 Execution timed out 1020 ms 67648 KB Time limit exceeded
83 Execution timed out 1106 ms 67620 KB Time limit exceeded
84 Execution timed out 1058 ms 67796 KB Time limit exceeded
85 Execution timed out 1040 ms 67596 KB Time limit exceeded
86 Execution timed out 1067 ms 67768 KB Time limit exceeded
87 Execution timed out 1008 ms 67468 KB Time limit exceeded
88 Execution timed out 1031 ms 67668 KB Time limit exceeded
89 Execution timed out 1039 ms 67544 KB Time limit exceeded
90 Execution timed out 1016 ms 43840 KB Time limit exceeded
91 Execution timed out 1104 ms 67776 KB Time limit exceeded
92 Execution timed out 1029 ms 67572 KB Time limit exceeded
93 Execution timed out 1053 ms 67544 KB Time limit exceeded
94 Execution timed out 1047 ms 67412 KB Time limit exceeded
95 Execution timed out 1085 ms 67816 KB Time limit exceeded
96 Execution timed out 1042 ms 67596 KB Time limit exceeded
97 Execution timed out 1059 ms 67584 KB Time limit exceeded
98 Execution timed out 1022 ms 67652 KB Time limit exceeded
99 Execution timed out 1063 ms 67668 KB Time limit exceeded
100 Execution timed out 1061 ms 67824 KB Time limit exceeded