Submission #169620

# Submission time Handle Problem Language Result Execution time Memory
169620 2019-12-21T16:38:12 Z davitmarg Bomb (IZhO17_bomb) C++17
0 / 100
1000 ms 49912 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];
char x;
pair<int, int> s;

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 = s.first * s.second / k, r = m, mid, pos = -1;
    while (l <= r)
    {
        mid = (l + r) / 2;
        if (check(k, mid))
        {
            if (k * mid >= s.first * s.second)
                s = MP(k, mid);
            l = mid + 1;
        }
        else
            r = mid - 1;
    }
}

int main()
{
    cin >> n >> m;
    s = MP(1, 1);
    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++)
        solve(i);
    cout << s.first << " " << s.second << endl;
    return 0;
}

/*
 
 
4 2
1921
 
 
*/

Compilation message

bomb.cpp: In function 'void solve(int)':
bomb.cpp:66:49: warning: unused variable 'pos' [-Wunused-variable]
     int l = s.first * s.second / k, r = m, mid, pos = -1;
                                                 ^~~
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 Incorrect 2 ms 376 KB Output isn't correct
2 Incorrect 2 ms 504 KB Output isn't correct
3 Incorrect 226 ms 20476 KB Output isn't correct
4 Incorrect 224 ms 20472 KB Output isn't correct
5 Incorrect 2 ms 376 KB Output isn't correct
6 Incorrect 2 ms 468 KB Output isn't correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Incorrect 2 ms 504 KB Output isn't correct
9 Incorrect 2 ms 476 KB Output isn't correct
10 Incorrect 2 ms 380 KB Output isn't correct
11 Incorrect 2 ms 504 KB Output isn't correct
12 Incorrect 2 ms 376 KB Output isn't correct
13 Incorrect 2 ms 504 KB Output isn't correct
14 Incorrect 2 ms 504 KB Output isn't correct
15 Incorrect 2 ms 504 KB Output isn't correct
16 Incorrect 2 ms 504 KB Output isn't correct
17 Incorrect 6 ms 976 KB Output isn't correct
18 Incorrect 6 ms 1016 KB Output isn't correct
19 Incorrect 10 ms 1144 KB Output isn't correct
20 Incorrect 8 ms 1144 KB Output isn't correct
21 Incorrect 5 ms 888 KB Output isn't correct
22 Incorrect 8 ms 1016 KB Output isn't correct
23 Incorrect 12 ms 1284 KB Output isn't correct
24 Incorrect 8 ms 1016 KB Output isn't correct
25 Incorrect 14 ms 1272 KB Output isn't correct
26 Incorrect 16 ms 1272 KB Output isn't correct
27 Incorrect 313 ms 3448 KB Output isn't correct
28 Incorrect 350 ms 3708 KB Output isn't correct
29 Incorrect 662 ms 4608 KB Output isn't correct
30 Incorrect 978 ms 5612 KB Output isn't correct
31 Incorrect 576 ms 4376 KB Output isn't correct
32 Incorrect 798 ms 5132 KB Output isn't correct
33 Execution timed out 1068 ms 5752 KB Time limit exceeded
34 Incorrect 288 ms 3964 KB Output isn't correct
35 Incorrect 936 ms 5888 KB Output isn't correct
36 Execution timed out 1075 ms 5800 KB Time limit exceeded
37 Incorrect 2 ms 504 KB Output isn't correct
38 Execution timed out 1053 ms 49688 KB Time limit exceeded
39 Incorrect 2 ms 504 KB Output isn't correct
40 Execution timed out 1062 ms 13688 KB Time limit exceeded
41 Incorrect 2 ms 504 KB Output isn't correct
42 Incorrect 15 ms 1272 KB Output isn't correct
43 Execution timed out 1062 ms 49724 KB Time limit exceeded
44 Execution timed out 1077 ms 5752 KB Time limit exceeded
45 Execution timed out 1082 ms 49680 KB Time limit exceeded
46 Execution timed out 1084 ms 49656 KB Time limit exceeded
47 Execution timed out 1086 ms 49656 KB Time limit exceeded
48 Execution timed out 1085 ms 49912 KB Time limit exceeded
49 Execution timed out 1076 ms 49668 KB Time limit exceeded
50 Execution timed out 1076 ms 49788 KB Time limit exceeded
51 Execution timed out 1081 ms 49716 KB Time limit exceeded
52 Execution timed out 1078 ms 49900 KB Time limit exceeded
53 Execution timed out 1081 ms 49728 KB Time limit exceeded
54 Execution timed out 1078 ms 49656 KB Time limit exceeded
55 Execution timed out 1078 ms 49796 KB Time limit exceeded
56 Execution timed out 1075 ms 49632 KB Time limit exceeded
57 Execution timed out 1090 ms 49656 KB Time limit exceeded
58 Execution timed out 1080 ms 49740 KB Time limit exceeded
59 Execution timed out 1093 ms 49656 KB Time limit exceeded
60 Execution timed out 1092 ms 49656 KB Time limit exceeded
61 Execution timed out 1084 ms 49804 KB Time limit exceeded
62 Execution timed out 1091 ms 49656 KB Time limit exceeded
63 Execution timed out 1089 ms 49660 KB Time limit exceeded
64 Execution timed out 1082 ms 49696 KB Time limit exceeded
65 Execution timed out 1091 ms 49912 KB Time limit exceeded
66 Execution timed out 1090 ms 49728 KB Time limit exceeded
67 Execution timed out 1083 ms 49820 KB Time limit exceeded
68 Execution timed out 1091 ms 49840 KB Time limit exceeded
69 Execution timed out 1080 ms 49792 KB Time limit exceeded
70 Execution timed out 1084 ms 39928 KB Time limit exceeded
71 Execution timed out 1082 ms 49656 KB Time limit exceeded
72 Execution timed out 1078 ms 49768 KB Time limit exceeded
73 Execution timed out 1086 ms 49656 KB Time limit exceeded
74 Execution timed out 1087 ms 49612 KB Time limit exceeded
75 Execution timed out 1080 ms 49716 KB Time limit exceeded
76 Execution timed out 1077 ms 49736 KB Time limit exceeded
77 Execution timed out 1092 ms 49740 KB Time limit exceeded
78 Execution timed out 1076 ms 49780 KB Time limit exceeded
79 Execution timed out 1078 ms 49756 KB Time limit exceeded
80 Execution timed out 1087 ms 49540 KB Time limit exceeded
81 Execution timed out 1077 ms 49452 KB Time limit exceeded
82 Execution timed out 1094 ms 49400 KB Time limit exceeded
83 Execution timed out 1092 ms 49276 KB Time limit exceeded
84 Execution timed out 1086 ms 49400 KB Time limit exceeded
85 Execution timed out 1085 ms 49400 KB Time limit exceeded
86 Execution timed out 1087 ms 49400 KB Time limit exceeded
87 Execution timed out 1081 ms 49372 KB Time limit exceeded
88 Execution timed out 1079 ms 49656 KB Time limit exceeded
89 Execution timed out 1069 ms 49712 KB Time limit exceeded
90 Execution timed out 1066 ms 39860 KB Time limit exceeded
91 Execution timed out 1077 ms 49784 KB Time limit exceeded
92 Execution timed out 1084 ms 49788 KB Time limit exceeded
93 Execution timed out 1084 ms 49676 KB Time limit exceeded
94 Execution timed out 1084 ms 49784 KB Time limit exceeded
95 Execution timed out 1080 ms 49684 KB Time limit exceeded
96 Execution timed out 1066 ms 49656 KB Time limit exceeded
97 Execution timed out 1082 ms 49676 KB Time limit exceeded
98 Execution timed out 1066 ms 49596 KB Time limit exceeded
99 Execution timed out 1055 ms 49820 KB Time limit exceeded
100 Execution timed out 1068 ms 49636 KB Time limit exceeded