답안 #855507

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855507 2023-10-01T11:21:54 Z Alfraganus Bomb (IZhO17_bomb) C++17
9 / 100
1000 ms 62556 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 = m;
    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;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 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 600 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 2 ms 348 KB Output isn't correct
24 Incorrect 1 ms 500 KB Output isn't correct
25 Incorrect 2 ms 348 KB Output isn't correct
26 Incorrect 2 ms 564 KB Output isn't correct
27 Correct 21 ms 1312 KB Output is correct
28 Incorrect 17 ms 1596 KB Output isn't correct
29 Incorrect 69 ms 1692 KB Output isn't correct
30 Incorrect 28 ms 2356 KB Output isn't correct
31 Incorrect 23 ms 2048 KB Output isn't correct
32 Incorrect 26 ms 2060 KB Output isn't correct
33 Incorrect 35 ms 2488 KB Output isn't correct
34 Incorrect 12 ms 1296 KB Output isn't correct
35 Incorrect 30 ms 2532 KB Output isn't correct
36 Incorrect 139 ms 2468 KB Output isn't correct
37 Incorrect 0 ms 344 KB Output isn't correct
38 Execution timed out 1095 ms 61980 KB Time limit exceeded
39 Incorrect 0 ms 348 KB Output isn't correct
40 Incorrect 702 ms 8188 KB Output isn't correct
41 Incorrect 0 ms 348 KB Output isn't correct
42 Incorrect 2 ms 348 KB Output isn't correct
43 Execution timed out 1098 ms 61880 KB Time limit exceeded
44 Incorrect 62 ms 2488 KB Output isn't correct
45 Execution timed out 1076 ms 61964 KB Time limit exceeded
46 Execution timed out 1068 ms 62032 KB Time limit exceeded
47 Execution timed out 1064 ms 61968 KB Time limit exceeded
48 Execution timed out 1037 ms 62036 KB Time limit exceeded
49 Execution timed out 1055 ms 61960 KB Time limit exceeded
50 Execution timed out 1048 ms 62072 KB Time limit exceeded
51 Execution timed out 1034 ms 61988 KB Time limit exceeded
52 Execution timed out 1075 ms 62108 KB Time limit exceeded
53 Execution timed out 1067 ms 62112 KB Time limit exceeded
54 Execution timed out 1070 ms 62116 KB Time limit exceeded
55 Execution timed out 1055 ms 61964 KB Time limit exceeded
56 Execution timed out 1035 ms 62168 KB Time limit exceeded
57 Execution timed out 1055 ms 62240 KB Time limit exceeded
58 Execution timed out 1022 ms 62184 KB Time limit exceeded
59 Execution timed out 1049 ms 62036 KB Time limit exceeded
60 Execution timed out 1071 ms 62140 KB Time limit exceeded
61 Execution timed out 1053 ms 62000 KB Time limit exceeded
62 Execution timed out 1077 ms 61780 KB Time limit exceeded
63 Execution timed out 1060 ms 61816 KB Time limit exceeded
64 Execution timed out 1050 ms 61840 KB Time limit exceeded
65 Execution timed out 1058 ms 62252 KB Time limit exceeded
66 Execution timed out 1022 ms 62300 KB Time limit exceeded
67 Execution timed out 1068 ms 62168 KB Time limit exceeded
68 Execution timed out 1056 ms 61960 KB Time limit exceeded
69 Execution timed out 1062 ms 61912 KB Time limit exceeded
70 Incorrect 910 ms 40080 KB Output isn't correct
71 Execution timed out 1077 ms 62448 KB Time limit exceeded
72 Execution timed out 1031 ms 62196 KB Time limit exceeded
73 Execution timed out 1064 ms 62064 KB Time limit exceeded
74 Execution timed out 1068 ms 62196 KB Time limit exceeded
75 Execution timed out 1083 ms 61896 KB Time limit exceeded
76 Execution timed out 1058 ms 62012 KB Time limit exceeded
77 Execution timed out 1030 ms 61908 KB Time limit exceeded
78 Execution timed out 1054 ms 62168 KB Time limit exceeded
79 Execution timed out 1072 ms 62256 KB Time limit exceeded
80 Execution timed out 1077 ms 62096 KB Time limit exceeded
81 Execution timed out 1067 ms 62072 KB Time limit exceeded
82 Execution timed out 1041 ms 62016 KB Time limit exceeded
83 Execution timed out 1063 ms 62556 KB Time limit exceeded
84 Execution timed out 1072 ms 62120 KB Time limit exceeded
85 Execution timed out 1056 ms 61812 KB Time limit exceeded
86 Execution timed out 1055 ms 62096 KB Time limit exceeded
87 Execution timed out 1048 ms 62040 KB Time limit exceeded
88 Execution timed out 1012 ms 61960 KB Time limit exceeded
89 Execution timed out 1020 ms 61804 KB Time limit exceeded
90 Execution timed out 1058 ms 40072 KB Time limit exceeded
91 Execution timed out 1080 ms 61884 KB Time limit exceeded
92 Execution timed out 1067 ms 61960 KB Time limit exceeded
93 Execution timed out 1029 ms 61880 KB Time limit exceeded
94 Execution timed out 1057 ms 61892 KB Time limit exceeded
95 Execution timed out 1050 ms 62040 KB Time limit exceeded
96 Execution timed out 1038 ms 62068 KB Time limit exceeded
97 Execution timed out 1072 ms 61916 KB Time limit exceeded
98 Execution timed out 1057 ms 61960 KB Time limit exceeded
99 Execution timed out 1045 ms 61880 KB Time limit exceeded
100 Execution timed out 1039 ms 61916 KB Time limit exceeded