Submission #100545

# Submission time Handle Problem Language Result Execution time Memory
100545 2019-03-12T07:30:50 Z alexpetrescu Bomb (IZhO17_bomb) C++14
24 / 100
571 ms 61688 KB
#include <cstdio>
#include <algorithm>

//FILE *fin = fopen("a.in", "r"), *fout = fopen("a.out", "w");
#define fin stdin
#define fout stdout

#define MAXN 2500

int left[MAXN + 2][MAXN + 2], right[MAXN + 2][MAXN + 2];
int d[MAXN + 2];
char m[MAXN + 2][MAXN + 10];
int nrlin, nrcol;

inline void solve() {
    for (int i = 1; i <= nrlin; i++) {
        left[i][0] = 0;
        for (int j = 1; j <= nrcol; j++)
            if (m[i][j] == '1')
                left[i][j] = left[i][j - 1];
            else
                left[i][j] = j;
        right[i][nrcol + 1] = nrcol + 1;
        for (int j = nrcol; j > 0; j--)
            if (m[i][j] == '1')
                right[i][j] = right[i][j + 1];
            else
                right[i][j] = j;

        for (int j = 1; j <= nrcol; j++)
            if (m[i][j] == '1')
                d[1] = std::min(d[1], right[i][j] - left[i][j] - 1);
    }

    for (int j = 1; j <= nrcol; j++) {
        int val = nrcol, cat = 0;
        for (int i = 1; i <= nrlin; i++) {
            if (m[i][j] == '1') {
                val = std::min(val, right[i][j] - left[i][j] - 1);
                cat++;
                d[cat] = std::min(d[cat], val);
            } else {
                if (cat)
                    d[cat + 1] = 0;
                val = nrcol;
                cat = 0;
            }
        }
    }
}

int main() {
    fscanf(fin, "%d%d ", &nrlin, &nrcol);

    for (int i = 1; i <= nrlin; i++)
        fgets(m[i] + 1, MAXN + 5, fin), d[i] = nrcol;

    solve();

    for (int i = 1; i <= nrlin / 2; i++)
        for (int j = 1; j <= nrcol; j++)
            std::swap(m[i][j], m[nrlin - i + 1][j]);

    solve();

    for (int i = 2; i <= nrlin; i++)
        d[i] = std::min(d[i], d[i - 1]);

    int ans = d[1];
    for (int i = 2; i <= nrlin; i++)
        ans = std::max(ans, i * d[i]);

    fprintf(fout, "%d\n", ans);

    fclose(fin);
    fclose(fout);
    return 0;
}

Compilation message

bomb.cpp: In function 'int main()':
bomb.cpp:53:11: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin, "%d%d ", &nrlin, &nrcol);
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bomb.cpp:56:39: warning: ignoring return value of 'char* fgets(char*, int, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         fgets(m[i] + 1, MAXN + 5, fin), d[i] = nrcol;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 21 ms 26624 KB Output is correct
4 Correct 22 ms 26496 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Incorrect 2 ms 512 KB Output isn't correct
9 Incorrect 2 ms 512 KB Output isn't correct
10 Incorrect 2 ms 512 KB Output isn't correct
11 Incorrect 2 ms 512 KB Output isn't correct
12 Incorrect 2 ms 512 KB Output isn't correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Incorrect 2 ms 512 KB Output isn't correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 3 ms 1024 KB Output is correct
18 Incorrect 3 ms 1152 KB Output isn't correct
19 Incorrect 4 ms 1408 KB Output isn't correct
20 Incorrect 4 ms 1408 KB Output isn't correct
21 Incorrect 2 ms 896 KB Output isn't correct
22 Incorrect 3 ms 1152 KB Output isn't correct
23 Incorrect 4 ms 1536 KB Output isn't correct
24 Incorrect 3 ms 1152 KB Output isn't correct
25 Incorrect 3 ms 1408 KB Output isn't correct
26 Correct 3 ms 1536 KB Output is correct
27 Correct 7 ms 4096 KB Output is correct
28 Incorrect 7 ms 4352 KB Output isn't correct
29 Incorrect 9 ms 5504 KB Output isn't correct
30 Incorrect 11 ms 6528 KB Output isn't correct
31 Incorrect 9 ms 5120 KB Output isn't correct
32 Incorrect 9 ms 6016 KB Output isn't correct
33 Incorrect 11 ms 6784 KB Output isn't correct
34 Incorrect 7 ms 4736 KB Output isn't correct
35 Incorrect 9 ms 6784 KB Output isn't correct
36 Correct 13 ms 6784 KB Output is correct
37 Incorrect 2 ms 512 KB Output isn't correct
38 Correct 534 ms 61604 KB Output is correct
39 Incorrect 3 ms 512 KB Output isn't correct
40 Incorrect 54 ms 16384 KB Output isn't correct
41 Incorrect 2 ms 512 KB Output isn't correct
42 Incorrect 3 ms 1408 KB Output isn't correct
43 Correct 426 ms 61556 KB Output is correct
44 Incorrect 11 ms 6784 KB Output isn't correct
45 Incorrect 391 ms 61560 KB Output isn't correct
46 Correct 335 ms 61560 KB Output is correct
47 Incorrect 375 ms 61560 KB Output isn't correct
48 Incorrect 363 ms 61688 KB Output isn't correct
49 Correct 555 ms 61560 KB Output is correct
50 Incorrect 399 ms 61688 KB Output isn't correct
51 Incorrect 389 ms 61596 KB Output isn't correct
52 Incorrect 369 ms 61640 KB Output isn't correct
53 Incorrect 405 ms 61560 KB Output isn't correct
54 Incorrect 290 ms 61560 KB Output isn't correct
55 Incorrect 275 ms 61644 KB Output isn't correct
56 Correct 506 ms 61688 KB Output is correct
57 Incorrect 251 ms 61680 KB Output isn't correct
58 Incorrect 258 ms 61552 KB Output isn't correct
59 Incorrect 240 ms 61560 KB Output isn't correct
60 Correct 346 ms 61560 KB Output is correct
61 Correct 571 ms 61560 KB Output is correct
62 Correct 538 ms 61576 KB Output is correct
63 Correct 523 ms 61660 KB Output is correct
64 Correct 263 ms 61560 KB Output is correct
65 Incorrect 353 ms 61580 KB Output isn't correct
66 Incorrect 333 ms 61560 KB Output isn't correct
67 Incorrect 393 ms 61452 KB Output isn't correct
68 Incorrect 402 ms 61560 KB Output isn't correct
69 Incorrect 235 ms 61688 KB Output isn't correct
70 Incorrect 120 ms 48376 KB Output isn't correct
71 Incorrect 192 ms 61688 KB Output isn't correct
72 Incorrect 228 ms 61560 KB Output isn't correct
73 Incorrect 229 ms 61560 KB Output isn't correct
74 Incorrect 227 ms 61556 KB Output isn't correct
75 Incorrect 235 ms 61560 KB Output isn't correct
76 Incorrect 233 ms 61588 KB Output isn't correct
77 Incorrect 273 ms 61680 KB Output isn't correct
78 Incorrect 257 ms 61688 KB Output isn't correct
79 Incorrect 130 ms 61560 KB Output isn't correct
80 Incorrect 146 ms 61584 KB Output isn't correct
81 Incorrect 135 ms 61560 KB Output isn't correct
82 Incorrect 263 ms 61672 KB Output isn't correct
83 Incorrect 244 ms 61560 KB Output isn't correct
84 Incorrect 122 ms 61560 KB Output isn't correct
85 Incorrect 241 ms 61576 KB Output isn't correct
86 Incorrect 537 ms 61660 KB Output isn't correct
87 Incorrect 250 ms 61612 KB Output isn't correct
88 Incorrect 243 ms 61560 KB Output isn't correct
89 Incorrect 356 ms 61560 KB Output isn't correct
90 Incorrect 140 ms 48248 KB Output isn't correct
91 Incorrect 305 ms 61560 KB Output isn't correct
92 Incorrect 339 ms 61588 KB Output isn't correct
93 Incorrect 489 ms 61560 KB Output isn't correct
94 Incorrect 308 ms 61560 KB Output isn't correct
95 Incorrect 246 ms 61564 KB Output isn't correct
96 Incorrect 283 ms 61560 KB Output isn't correct
97 Incorrect 540 ms 61568 KB Output isn't correct
98 Incorrect 286 ms 61560 KB Output isn't correct
99 Incorrect 336 ms 61564 KB Output isn't correct
100 Incorrect 515 ms 61560 KB Output isn't correct