Submission #169625

# Submission time Handle Problem Language Result Execution time Memory
169625 2019-12-21T16:52:36 Z davitmarg Bomb (IZhO17_bomb) C++17
66 / 100
912 ms 98652 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
        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 380 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 37 ms 40440 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 376 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 680 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 2 ms 636 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 1528 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 1912 KB Output is correct
26 Correct 7 ms 2168 KB Output is correct
27 Correct 14 ms 6264 KB Output is correct
28 Correct 29 ms 3932 KB Output is correct
29 Correct 254 ms 8312 KB Output is correct
30 Correct 437 ms 8056 KB Output is correct
31 Correct 253 ms 6136 KB Output is correct
32 Correct 402 ms 7672 KB Output is correct
33 Correct 665 ms 9592 KB Output is correct
34 Correct 25 ms 4344 KB Output is correct
35 Correct 87 ms 6136 KB Output is correct
36 Correct 413 ms 10872 KB Output is correct
37 Correct 2 ms 632 KB Output is correct
38 Correct 784 ms 98652 KB Output is correct
39 Correct 2 ms 632 KB Output is correct
40 Incorrect 101 ms 26488 KB Output isn't correct
41 Correct 2 ms 632 KB Output is correct
42 Correct 12 ms 2044 KB Output is correct
43 Correct 794 ms 94580 KB Output is correct
44 Correct 911 ms 10232 KB Output is correct
45 Incorrect 613 ms 95992 KB Output isn't correct
46 Correct 668 ms 98420 KB Output is correct
47 Incorrect 611 ms 95928 KB Output isn't correct
48 Correct 718 ms 98312 KB Output is correct
49 Correct 721 ms 98424 KB Output is correct
50 Correct 735 ms 98424 KB Output is correct
51 Correct 840 ms 98428 KB Output is correct
52 Correct 749 ms 98424 KB Output is correct
53 Correct 789 ms 97808 KB Output is correct
54 Correct 748 ms 85272 KB Output is correct
55 Correct 809 ms 83296 KB Output is correct
56 Correct 575 ms 98524 KB Output is correct
57 Correct 800 ms 78456 KB Output is correct
58 Correct 798 ms 83468 KB Output is correct
59 Correct 838 ms 80480 KB Output is correct
60 Correct 684 ms 90104 KB Output is correct
61 Correct 779 ms 98424 KB Output is correct
62 Correct 912 ms 98488 KB Output is correct
63 Correct 830 ms 98424 KB Output is correct
64 Correct 702 ms 81400 KB Output is correct
65 Correct 787 ms 97556 KB Output is correct
66 Correct 748 ms 94456 KB Output is correct
67 Correct 844 ms 98420 KB Output is correct
68 Correct 790 ms 98356 KB Output is correct
69 Correct 771 ms 78028 KB Output is correct
70 Incorrect 386 ms 49588 KB Output isn't correct
71 Incorrect 614 ms 71032 KB Output isn't correct
72 Incorrect 606 ms 76536 KB Output isn't correct
73 Incorrect 591 ms 77076 KB Output isn't correct
74 Incorrect 634 ms 78580 KB Output isn't correct
75 Incorrect 616 ms 80120 KB Output isn't correct
76 Incorrect 640 ms 81500 KB Output isn't correct
77 Incorrect 636 ms 82012 KB Output isn't correct
78 Incorrect 633 ms 82296 KB Output isn't correct
79 Incorrect 606 ms 54804 KB Output isn't correct
80 Incorrect 582 ms 56028 KB Output isn't correct
81 Incorrect 595 ms 56508 KB Output isn't correct
82 Incorrect 620 ms 84828 KB Output isn't correct
83 Incorrect 630 ms 84832 KB Output isn't correct
84 Incorrect 588 ms 49984 KB Output isn't correct
85 Incorrect 626 ms 83944 KB Output isn't correct
86 Incorrect 701 ms 97400 KB Output isn't correct
87 Incorrect 637 ms 82880 KB Output isn't correct
88 Incorrect 592 ms 83620 KB Output isn't correct
89 Incorrect 647 ms 92392 KB Output isn't correct
90 Incorrect 426 ms 63780 KB Output isn't correct
91 Incorrect 642 ms 87644 KB Output isn't correct
92 Incorrect 650 ms 89252 KB Output isn't correct
93 Incorrect 697 ms 96376 KB Output isn't correct
94 Incorrect 666 ms 91040 KB Output isn't correct
95 Incorrect 667 ms 85024 KB Output isn't correct
96 Incorrect 619 ms 84676 KB Output isn't correct
97 Incorrect 775 ms 97304 KB Output isn't correct
98 Incorrect 701 ms 84400 KB Output isn't correct
99 Incorrect 679 ms 90848 KB Output isn't correct
100 Incorrect 702 ms 95944 KB Output isn't correct