Submission #100544

# Submission time Handle Problem Language Result Execution time Memory
100544 2019-03-12T07:30:05 Z alexpetrescu Bomb (IZhO17_bomb) C++14
0 / 100
6 ms 512 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 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 6 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
21 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Runtime error 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
25 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
27 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
28 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
29 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
30 Runtime error 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Runtime error 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
33 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
35 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
37 Runtime error 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
38 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
39 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Runtime error 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
42 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
43 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
44 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
45 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
46 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
47 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
49 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
50 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
51 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
52 Runtime error 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
54 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
55 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
56 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
57 Runtime error 4 ms 372 KB Execution killed with signal 11 (could be triggered by violating memory limits)
58 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
59 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
60 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
61 Runtime error 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
62 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
63 Runtime error 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
64 Runtime error 6 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
65 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
66 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
67 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
68 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
69 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
70 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
71 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
72 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
73 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
74 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
75 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
76 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
77 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
78 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
79 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
80 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
81 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
82 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
83 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
84 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
85 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
86 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
87 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
88 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
89 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
90 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
91 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
92 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
93 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
94 Runtime error 5 ms 484 KB Execution killed with signal 11 (could be triggered by violating memory limits)
95 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
96 Runtime error 4 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
97 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
98 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
99 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
100 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)