Submission #855546

# Submission time Handle Problem Language Result Execution time Memory
855546 2023-10-01T12:02:35 Z Alfraganus Bomb (IZhO17_bomb) C++17
21 / 100
1000 ms 67396 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;
    }
}

Compilation message

bomb.cpp: In function 'bool f1(long long int, long long int)':
bomb.cpp:74:16: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   74 |             if (SUM(i, j, x, y) == x * y)
      |                ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 1 ms 348 KB Output is correct
6 Correct 0 ms 372 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 1 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 0 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 464 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 Correct 2 ms 348 KB Output is correct
27 Correct 14 ms 1336 KB Output is correct
28 Incorrect 12 ms 1492 KB Output isn't correct
29 Incorrect 45 ms 1628 KB Output isn't correct
30 Incorrect 13 ms 2512 KB Output isn't correct
31 Incorrect 10 ms 2096 KB Output isn't correct
32 Incorrect 11 ms 2148 KB Output isn't correct
33 Incorrect 17 ms 2668 KB Output isn't correct
34 Incorrect 6 ms 1116 KB Output isn't correct
35 Incorrect 14 ms 2684 KB Output isn't correct
36 Correct 130 ms 2684 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 426 ms 66976 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Incorrect 508 ms 8884 KB Output isn't correct
41 Correct 1 ms 344 KB Output is correct
42 Incorrect 1 ms 348 KB Output isn't correct
43 Execution timed out 1067 ms 66948 KB Time limit exceeded
44 Incorrect 37 ms 2688 KB Output isn't correct
45 Execution timed out 1020 ms 67012 KB Time limit exceeded
46 Correct 625 ms 66956 KB Output is correct
47 Execution timed out 1037 ms 67088 KB Time limit exceeded
48 Execution timed out 1035 ms 67172 KB Time limit exceeded
49 Execution timed out 1044 ms 66948 KB Time limit exceeded
50 Execution timed out 1085 ms 66956 KB Time limit exceeded
51 Execution timed out 1048 ms 67144 KB Time limit exceeded
52 Execution timed out 1022 ms 67028 KB Time limit exceeded
53 Execution timed out 1020 ms 67044 KB Time limit exceeded
54 Execution timed out 1103 ms 66952 KB Time limit exceeded
55 Execution timed out 1024 ms 67152 KB Time limit exceeded
56 Correct 676 ms 66988 KB Output is correct
57 Execution timed out 1027 ms 66996 KB Time limit exceeded
58 Execution timed out 1035 ms 66996 KB Time limit exceeded
59 Execution timed out 1081 ms 67252 KB Time limit exceeded
60 Execution timed out 1091 ms 67088 KB Time limit exceeded
61 Execution timed out 1020 ms 67132 KB Time limit exceeded
62 Execution timed out 1060 ms 66904 KB Time limit exceeded
63 Execution timed out 1033 ms 66912 KB Time limit exceeded
64 Correct 802 ms 66952 KB Output is correct
65 Execution timed out 1028 ms 66944 KB Time limit exceeded
66 Execution timed out 1093 ms 66952 KB Time limit exceeded
67 Execution timed out 1077 ms 67036 KB Time limit exceeded
68 Execution timed out 1045 ms 67156 KB Time limit exceeded
69 Execution timed out 1036 ms 66956 KB Time limit exceeded
70 Incorrect 427 ms 42960 KB Output isn't correct
71 Incorrect 840 ms 67188 KB Output isn't correct
72 Incorrect 883 ms 67216 KB Output isn't correct
73 Incorrect 671 ms 67396 KB Output isn't correct
74 Incorrect 698 ms 67128 KB Output isn't correct
75 Execution timed out 1046 ms 66952 KB Time limit exceeded
76 Incorrect 658 ms 67032 KB Output isn't correct
77 Execution timed out 1008 ms 66992 KB Time limit exceeded
78 Incorrect 650 ms 66948 KB Output isn't correct
79 Incorrect 626 ms 67112 KB Output isn't correct
80 Incorrect 619 ms 66964 KB Output isn't correct
81 Incorrect 642 ms 67204 KB Output isn't correct
82 Execution timed out 1018 ms 67164 KB Time limit exceeded
83 Incorrect 602 ms 67112 KB Output isn't correct
84 Incorrect 595 ms 67132 KB Output isn't correct
85 Execution timed out 1035 ms 67064 KB Time limit exceeded
86 Execution timed out 1056 ms 67000 KB Time limit exceeded
87 Execution timed out 1043 ms 66948 KB Time limit exceeded
88 Incorrect 929 ms 67184 KB Output isn't correct
89 Execution timed out 1052 ms 67076 KB Time limit exceeded
90 Incorrect 843 ms 43048 KB Output isn't correct
91 Execution timed out 1056 ms 66948 KB Time limit exceeded
92 Execution timed out 1042 ms 66988 KB Time limit exceeded
93 Execution timed out 1008 ms 66952 KB Time limit exceeded
94 Execution timed out 1016 ms 66908 KB Time limit exceeded
95 Incorrect 764 ms 66944 KB Output isn't correct
96 Incorrect 653 ms 66948 KB Output isn't correct
97 Execution timed out 1102 ms 66940 KB Time limit exceeded
98 Execution timed out 1014 ms 66956 KB Time limit exceeded
99 Execution timed out 1010 ms 67076 KB Time limit exceeded
100 Execution timed out 1100 ms 66984 KB Time limit exceeded