Submission #38432

# Submission time Handle Problem Language Result Execution time Memory
38432 2018-01-04T06:09:24 Z Talant Bomb (IZhO17_bomb) C++14
48 / 100
1000 ms 130980 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)1e6 + 10;

int n,m;
char a[2502][2502];
int c[2502][2502];

int mx,mn = inf,mn1 = inf;
vector <pair<int,int> > v;

bool check (int h,int w) {
        for (int l = 0; l < v.size(); l ++) {
                int f = 0;
                for (int i = max(v[l].fr,h); i <= min(n,v[l].fr + h - 1); i ++) {
                        for (int j = max(w,v[l].sc); j <= min(m,v[l].sc + w - 1); j ++) {
                                if (i - h < 0)
                                        continue;
                                if (j - w < 0)
                                        continue;
                                if (c[i][j] - c[i - h][j] - c[i][j - w] + c[i - h][j - w] == (h * w)) {
                                        f = 1;
                                        break;
                                }
                        }
                        if (f == 1)
                                break;
                }
                if (!f)
                        return false;
        }
        return true;
}
int main () {
        cin >> n >> m;

        for (int i = 1; i <= n; i ++)
                scanf ("%s", a[i] + 1);

        for (int i = 1; i <= n; i ++) {
                int cnt = 0;
                for (int j = 1; j <= m; j ++) {
                        c[i][j] = int(a[i][j] - '0');
                        if (c[i][j] == 1)
                                v.pb(mk(i,j));
                        if (c[i][j] == 1)
                                cnt ++;
                        else {
                                if (cnt > 0)
                                mn = min(mn,cnt);
                        cnt = 0;
                        }
                }
                if (cnt > 0)
                        mn = min(mn,cnt);
        }
        for (int i = 1; i <= m; i ++) {
                int cnt = 0;
                for (int j = 1; j <= n; j ++) {
                        if (c[j][i] == 1)
                                cnt ++;
                        else {
                                if (cnt > 0)
                                mn1 = min(mn1,cnt);
                        cnt = 0;
                        }
                }
                if (cnt > 0)
                        mn1 = min(mn1,cnt);
        }
        if (mn == inf)
                mn = 0;
        if (mn1 == inf)
                mn1 = 0;

        if (mn * mn1 == 0) {
                cout << 0;
                return 0;
        }

        if (check(mn1,mn)) {
                cout << mn1 * mn;
                return 0;
        }

        for (int i = 1; i <= n; i ++)
                for (int j = 2; j <= m; j ++)
                        c[i][j] += c[i][j - 1];

        for (int i = 2; i <= n; i ++)
                for (int j = 1; j <= m; j ++)
                        c[i][j] += c[i - 1][j];


        for (int i = mn * mn1; i >= 1; i --) {
                for (int l = 1; l <= sqrt(i); l ++) {
                        if ((i) % l == 0 && (check((i) / l,l) || check(l,i / l))) {
                                cout << i << endl;
                                return 0;
                        }
                }
        }
        cout << 0 << endl;
}

Compilation message

bomb.cpp: In function 'bool check(int, int)':
bomb.cpp:24:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int l = 0; l < v.size(); l ++) {
                           ^
bomb.cpp: In function 'int main()':
bomb.cpp:49:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf ("%s", a[i] + 1);
                                       ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 32592 KB Output is correct
2 Correct 0 ms 32592 KB Output is correct
3 Correct 3 ms 32732 KB Output is correct
4 Correct 6 ms 32732 KB Output is correct
5 Correct 0 ms 32732 KB Output is correct
6 Correct 0 ms 32592 KB Output is correct
7 Correct 0 ms 32592 KB Output is correct
8 Correct 0 ms 32592 KB Output is correct
9 Correct 0 ms 32592 KB Output is correct
10 Correct 0 ms 32592 KB Output is correct
11 Correct 0 ms 32592 KB Output is correct
12 Correct 0 ms 32592 KB Output is correct
13 Correct 0 ms 32592 KB Output is correct
14 Correct 0 ms 32592 KB Output is correct
15 Correct 0 ms 32592 KB Output is correct
16 Correct 0 ms 32592 KB Output is correct
17 Correct 0 ms 32592 KB Output is correct
18 Correct 0 ms 32592 KB Output is correct
19 Correct 0 ms 32592 KB Output is correct
20 Correct 0 ms 32592 KB Output is correct
21 Correct 0 ms 32592 KB Output is correct
22 Correct 0 ms 32592 KB Output is correct
23 Correct 3 ms 32732 KB Output is correct
24 Correct 0 ms 32592 KB Output is correct
25 Correct 16 ms 32732 KB Output is correct
26 Correct 0 ms 32864 KB Output is correct
27 Correct 0 ms 34212 KB Output is correct
28 Correct 3 ms 32592 KB Output is correct
29 Execution timed out 1000 ms 34212 KB Execution timed out
30 Execution timed out 1000 ms 33444 KB Execution timed out
31 Execution timed out 1000 ms 33060 KB Execution timed out
32 Correct 483 ms 33060 KB Output is correct
33 Execution timed out 1000 ms 33444 KB Execution timed out
34 Correct 3 ms 32592 KB Output is correct
35 Correct 119 ms 32864 KB Output is correct
36 Correct 6 ms 35748 KB Output is correct
37 Correct 0 ms 32592 KB Output is correct
38 Correct 263 ms 130980 KB Output is correct
39 Correct 0 ms 32592 KB Output is correct
40 Execution timed out 1000 ms 44964 KB Execution timed out
41 Correct 0 ms 32592 KB Output is correct
42 Correct 133 ms 32732 KB Output is correct
43 Execution timed out 1000 ms 130980 KB Execution timed out
44 Execution timed out 1000 ms 34212 KB Execution timed out
45 Execution timed out 1000 ms 81828 KB Execution timed out
46 Execution timed out 1000 ms 81828 KB Execution timed out
47 Execution timed out 1000 ms 81828 KB Execution timed out
48 Execution timed out 1000 ms 81828 KB Execution timed out
49 Correct 273 ms 130980 KB Output is correct
50 Execution timed out 1000 ms 81828 KB Execution timed out
51 Execution timed out 1000 ms 81828 KB Execution timed out
52 Execution timed out 1000 ms 81828 KB Execution timed out
53 Execution timed out 1000 ms 81828 KB Execution timed out
54 Execution timed out 1000 ms 57252 KB Execution timed out
55 Execution timed out 1000 ms 57252 KB Execution timed out
56 Correct 593 ms 130980 KB Output is correct
57 Execution timed out 1000 ms 57252 KB Execution timed out
58 Execution timed out 1000 ms 57252 KB Execution timed out
59 Execution timed out 1000 ms 57252 KB Execution timed out
60 Correct 213 ms 81828 KB Output is correct
61 Correct 676 ms 130980 KB Output is correct
62 Execution timed out 1000 ms 130980 KB Execution timed out
63 Execution timed out 1000 ms 130980 KB Execution timed out
64 Correct 326 ms 57252 KB Output is correct
65 Execution timed out 1000 ms 81828 KB Execution timed out
66 Execution timed out 1000 ms 81828 KB Execution timed out
67 Execution timed out 1000 ms 81828 KB Execution timed out
68 Execution timed out 1000 ms 130980 KB Execution timed out
69 Execution timed out 1000 ms 57252 KB Execution timed out
70 Execution timed out 1000 ms 38820 KB Execution timed out
71 Execution timed out 1000 ms 44964 KB Execution timed out
72 Execution timed out 1000 ms 57252 KB Execution timed out
73 Execution timed out 1000 ms 57252 KB Execution timed out
74 Execution timed out 1000 ms 57252 KB Execution timed out
75 Execution timed out 1000 ms 57252 KB Execution timed out
76 Execution timed out 1000 ms 57252 KB Execution timed out
77 Execution timed out 1000 ms 57252 KB Execution timed out
78 Execution timed out 1000 ms 57252 KB Execution timed out
79 Correct 386 ms 33060 KB Output is correct
80 Execution timed out 1000 ms 33060 KB Execution timed out
81 Execution timed out 1000 ms 35748 KB Execution timed out
82 Execution timed out 1000 ms 57252 KB Execution timed out
83 Execution timed out 1000 ms 57252 KB Execution timed out
84 Correct 526 ms 32864 KB Output is correct
85 Execution timed out 1000 ms 57252 KB Execution timed out
86 Correct 323 ms 130980 KB Output is correct
87 Execution timed out 1000 ms 57252 KB Execution timed out
88 Execution timed out 1000 ms 57252 KB Execution timed out
89 Execution timed out 1000 ms 81828 KB Execution timed out
90 Execution timed out 1000 ms 44964 KB Execution timed out
91 Execution timed out 1000 ms 81828 KB Execution timed out
92 Execution timed out 1000 ms 81828 KB Execution timed out
93 Correct 429 ms 130980 KB Output is correct
94 Execution timed out 1000 ms 81828 KB Execution timed out
95 Execution timed out 1000 ms 57252 KB Execution timed out
96 Execution timed out 1000 ms 57252 KB Execution timed out
97 Correct 346 ms 130980 KB Output is correct
98 Execution timed out 1000 ms 57252 KB Execution timed out
99 Execution timed out 1000 ms 81828 KB Execution timed out
100 Correct 396 ms 130980 KB Output is correct