Submission #855548

# Submission time Handle Problem Language Result Execution time Memory
855548 2023-10-01T12:05:12 Z Alfraganus Bomb (IZhO17_bomb) C++17
21 / 100
1000 ms 62256 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;
vector<vector<int>> sum;
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(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;
    for(int i = n - 1; i >= x - 1; i --)
        for(int j = y - 1; j < m; j ++)
            if (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];
    sum.resize(n, vector<int> (m));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            if (a[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]);
    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;
    }
}
# 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 1 ms 860 KB Output is correct
4 Correct 1 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 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Correct 0 ms 348 KB Output is correct
11 Incorrect 0 ms 348 KB Output isn't correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is 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 344 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 0 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 Correct 2 ms 348 KB Output is correct
27 Correct 17 ms 1264 KB Output is correct
28 Incorrect 8 ms 1372 KB Output isn't correct
29 Incorrect 45 ms 1724 KB Output isn't correct
30 Incorrect 21 ms 2448 KB Output isn't correct
31 Incorrect 11 ms 1944 KB Output isn't correct
32 Incorrect 11 ms 2000 KB Output isn't correct
33 Incorrect 17 ms 2476 KB Output isn't correct
34 Incorrect 6 ms 1112 KB Output isn't correct
35 Incorrect 14 ms 2488 KB Output isn't correct
36 Correct 137 ms 2488 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 472 ms 61976 KB Output is correct
39 Correct 0 ms 600 KB Output is correct
40 Incorrect 493 ms 8084 KB Output isn't correct
41 Correct 1 ms 348 KB Output is correct
42 Incorrect 1 ms 348 KB Output isn't correct
43 Execution timed out 1055 ms 61868 KB Time limit exceeded
44 Incorrect 37 ms 2672 KB Output isn't correct
45 Execution timed out 1053 ms 61860 KB Time limit exceeded
46 Correct 620 ms 61908 KB Output is correct
47 Execution timed out 1062 ms 61952 KB Time limit exceeded
48 Execution timed out 1056 ms 62164 KB Time limit exceeded
49 Execution timed out 1057 ms 61864 KB Time limit exceeded
50 Execution timed out 1076 ms 62056 KB Time limit exceeded
51 Execution timed out 1022 ms 61876 KB Time limit exceeded
52 Execution timed out 1050 ms 61860 KB Time limit exceeded
53 Execution timed out 1076 ms 61876 KB Time limit exceeded
54 Execution timed out 1059 ms 61896 KB Time limit exceeded
55 Execution timed out 1035 ms 61884 KB Time limit exceeded
56 Correct 680 ms 61876 KB Output is correct
57 Execution timed out 1016 ms 62024 KB Time limit exceeded
58 Execution timed out 1055 ms 62060 KB Time limit exceeded
59 Execution timed out 1046 ms 62004 KB Time limit exceeded
60 Execution timed out 1044 ms 61964 KB Time limit exceeded
61 Execution timed out 1057 ms 62040 KB Time limit exceeded
62 Execution timed out 1062 ms 61780 KB Time limit exceeded
63 Execution timed out 1068 ms 61772 KB Time limit exceeded
64 Correct 814 ms 61840 KB Output is correct
65 Execution timed out 1038 ms 62048 KB Time limit exceeded
66 Execution timed out 1044 ms 61860 KB Time limit exceeded
67 Execution timed out 1045 ms 61968 KB Time limit exceeded
68 Execution timed out 1035 ms 62040 KB Time limit exceeded
69 Execution timed out 1060 ms 61868 KB Time limit exceeded
70 Incorrect 437 ms 39756 KB Output isn't correct
71 Incorrect 828 ms 61880 KB Output isn't correct
72 Incorrect 874 ms 61884 KB Output isn't correct
73 Incorrect 667 ms 61988 KB Output isn't correct
74 Incorrect 691 ms 62104 KB Output isn't correct
75 Execution timed out 1068 ms 62096 KB Time limit exceeded
76 Incorrect 611 ms 61848 KB Output isn't correct
77 Execution timed out 1062 ms 61972 KB Time limit exceeded
78 Incorrect 643 ms 61876 KB Output isn't correct
79 Incorrect 634 ms 61880 KB Output isn't correct
80 Incorrect 631 ms 61876 KB Output isn't correct
81 Incorrect 642 ms 61952 KB Output isn't correct
82 Execution timed out 1030 ms 62088 KB Time limit exceeded
83 Incorrect 592 ms 62256 KB Output isn't correct
84 Incorrect 587 ms 61872 KB Output isn't correct
85 Execution timed out 1061 ms 61800 KB Time limit exceeded
86 Execution timed out 1027 ms 61964 KB Time limit exceeded
87 Execution timed out 1047 ms 62044 KB Time limit exceeded
88 Incorrect 944 ms 61908 KB Output isn't correct
89 Execution timed out 1082 ms 62036 KB Time limit exceeded
90 Incorrect 860 ms 39808 KB Output isn't correct
91 Execution timed out 1073 ms 61864 KB Time limit exceeded
92 Execution timed out 1031 ms 61880 KB Time limit exceeded
93 Execution timed out 1046 ms 61876 KB Time limit exceeded
94 Execution timed out 1033 ms 61868 KB Time limit exceeded
95 Incorrect 759 ms 61960 KB Output isn't correct
96 Incorrect 663 ms 61944 KB Output isn't correct
97 Execution timed out 1052 ms 62004 KB Time limit exceeded
98 Execution timed out 1062 ms 61904 KB Time limit exceeded
99 Execution timed out 1073 ms 61788 KB Time limit exceeded
100 Execution timed out 1100 ms 61796 KB Time limit exceeded