Submission #169629

# Submission time Handle Problem Language Result Execution time Memory
169629 2019-12-21T16:59:55 Z davitmarg Bomb (IZhO17_bomb) C++17
61 / 100
1000 ms 98552 KB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 2505;

int n, m, a[N][N], pr[N][N], lst[N][N], nxt[N][N];
char x;
int ans = 1;

void add(int sy, int sx, int y, int x)
{
    pr[sy][sx]++;
    pr[y][x]++;
    pr[sy][x]--;
    pr[y][sx]--;
}

int get(int sy, int sx, int y, int x)
{
    return a[y][x] - a[sy - 1][x] - a[y][sx - 1] + a[sy - 1][sx - 1];
}

bool check(int k, int q)
{
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            pr[i][j] = 0;
    for (int i = 1; i + k - 1 <= n; i++)
        for (int j = 1; j + q - 1 <= m; j++)
            if (get(i, j, i + k - 1, j + q - 1) == k * q)
                add(i, j, i + k, j + q);
    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];
            if (get(i, j, i, j) != (bool)(pr[i][j]))
                return 0;
        }
    return 1;
}

void solve(int k)
{
    int l = max(ans / k, 1), r = m, mid;
    while (l <= r)
    {
        mid = (l + r) / 2;
        if (check(k, mid))
        {
            if (k * mid >= ans)
                ans = k * mid;
            l = mid + 1;
        }
        else
            r = mid - 1;
    }
}

int main()
{
    cin >> n >> m;

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            scanf(" %c", &x);
            a[i][j] += (x - '0');
            a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
        }

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (get(i, j, i, j))
                lst[i][j] = 1 + lst[i - 1][j];

    int len = n;
    for (int i = n; i >= 1; i--)
        for (int j = m; j >= 1; j--)
            if (get(i, j, i, j))
            {
                nxt[i][j] = 1 + nxt[i + 1][j];
                len = min(len, nxt[i][j] + lst[i][j] - 1);
            }
    if (n <= 450)
        for (int i = 1; i <= len; i++)
            solve(i);
    else
    {
        for (int i = 1; i < len; i++)
            if (rand() % 150 == 0)
                solve(i);
        solve(len);
    }
    cout << ans << endl;
    return 0;
}

/*
 
6 6
000111
000111
001111
111100
111000
111000
 
*/

Compilation message

bomb.cpp: In function 'int main()':
bomb.cpp:88:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %c", &x);
             ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 37 ms 40568 KB Output is correct
4 Correct 37 ms 40440 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 632 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 632 KB Output is correct
16 Correct 2 ms 632 KB Output is correct
17 Correct 3 ms 1400 KB Output is correct
18 Correct 3 ms 1272 KB Output is correct
19 Correct 6 ms 1656 KB Output is correct
20 Correct 6 ms 1660 KB Output is correct
21 Correct 3 ms 888 KB Output is correct
22 Correct 4 ms 1272 KB Output is correct
23 Correct 7 ms 1656 KB Output is correct
24 Correct 5 ms 1528 KB Output is correct
25 Correct 10 ms 2040 KB Output is correct
26 Correct 7 ms 2168 KB Output is correct
27 Correct 14 ms 6236 KB Output is correct
28 Correct 29 ms 3960 KB Output is correct
29 Correct 252 ms 8312 KB Output is correct
30 Correct 432 ms 8184 KB Output is correct
31 Correct 250 ms 6136 KB Output is correct
32 Correct 396 ms 7544 KB Output is correct
33 Correct 655 ms 9460 KB Output is correct
34 Correct 25 ms 4344 KB Output is correct
35 Correct 85 ms 6136 KB Output is correct
36 Correct 414 ms 10872 KB Output is correct
37 Correct 2 ms 632 KB Output is correct
38 Execution timed out 1099 ms 98364 KB Time limit exceeded
39 Correct 2 ms 632 KB Output is correct
40 Incorrect 114 ms 26488 KB Output isn't correct
41 Correct 2 ms 632 KB Output is correct
42 Correct 12 ms 2040 KB Output is correct
43 Execution timed out 1087 ms 94412 KB Time limit exceeded
44 Correct 911 ms 10208 KB Output is correct
45 Execution timed out 1090 ms 95820 KB Time limit exceeded
46 Correct 644 ms 98552 KB Output is correct
47 Execution timed out 1077 ms 95992 KB Time limit exceeded
48 Correct 695 ms 98468 KB Output is correct
49 Correct 697 ms 98544 KB Output is correct
50 Correct 709 ms 98440 KB Output is correct
51 Correct 810 ms 98524 KB Output is correct
52 Correct 715 ms 98448 KB Output is correct
53 Correct 763 ms 97812 KB Output is correct
54 Correct 716 ms 85240 KB Output is correct
55 Correct 782 ms 83448 KB Output is correct
56 Execution timed out 1077 ms 98464 KB Time limit exceeded
57 Correct 817 ms 78712 KB Output is correct
58 Correct 774 ms 83584 KB Output is correct
59 Correct 807 ms 80476 KB Output is correct
60 Correct 657 ms 90232 KB Output is correct
61 Correct 754 ms 98324 KB Output is correct
62 Execution timed out 1095 ms 98424 KB Time limit exceeded
63 Execution timed out 1085 ms 98472 KB Time limit exceeded
64 Correct 673 ms 81264 KB Output is correct
65 Correct 765 ms 97400 KB Output is correct
66 Correct 694 ms 94344 KB Output is correct
67 Correct 807 ms 98552 KB Output is correct
68 Correct 748 ms 98356 KB Output is correct
69 Correct 743 ms 78016 KB Output is correct
70 Incorrect 621 ms 49656 KB Output isn't correct
71 Incorrect 958 ms 71244 KB Output isn't correct
72 Execution timed out 1084 ms 76484 KB Time limit exceeded
73 Execution timed out 1079 ms 76980 KB Time limit exceeded
74 Execution timed out 1078 ms 78584 KB Time limit exceeded
75 Execution timed out 1079 ms 80264 KB Time limit exceeded
76 Execution timed out 1086 ms 81488 KB Time limit exceeded
77 Execution timed out 1092 ms 82040 KB Time limit exceeded
78 Execution timed out 1092 ms 82168 KB Time limit exceeded
79 Incorrect 557 ms 54648 KB Output isn't correct
80 Incorrect 557 ms 56132 KB Output isn't correct
81 Incorrect 563 ms 56312 KB Output isn't correct
82 Execution timed out 1093 ms 84728 KB Time limit exceeded
83 Execution timed out 1085 ms 84788 KB Time limit exceeded
84 Incorrect 554 ms 50040 KB Output isn't correct
85 Incorrect 993 ms 83704 KB Output isn't correct
86 Incorrect 675 ms 97320 KB Output isn't correct
87 Incorrect 990 ms 82676 KB Output isn't correct
88 Execution timed out 1082 ms 83576 KB Time limit exceeded
89 Incorrect 622 ms 92408 KB Output isn't correct
90 Incorrect 704 ms 64020 KB Output isn't correct
91 Execution timed out 1022 ms 87488 KB Time limit exceeded
92 Execution timed out 1044 ms 89272 KB Time limit exceeded
93 Incorrect 676 ms 96412 KB Output isn't correct
94 Incorrect 828 ms 91120 KB Output isn't correct
95 Execution timed out 1068 ms 85068 KB Time limit exceeded
96 Execution timed out 1067 ms 84728 KB Time limit exceeded
97 Incorrect 679 ms 97216 KB Output isn't correct
98 Execution timed out 1087 ms 84472 KB Time limit exceeded
99 Incorrect 837 ms 90744 KB Output isn't correct
100 Incorrect 671 ms 96028 KB Output isn't correct