Submission #43065

# Submission time Handle Problem Language Result Execution time Memory
43065 2018-03-08T16:41:21 Z cheater2k Bomb (IZhO17_bomb) C++14
23 / 100
1000 ms 131072 KB
#include <bits/stdc++.h>
using namespace std;

#define left __left
#define right __right

const int N = 2505;
const int dx[] = {0, 0, -1, +1};
const int dy[] = {-1, +1, 0, 0};

int n, m, nrow, ncol;
int left[N][N];
int right[N][N];
int up[N][N];
int down[N][N];
char a[N][N];
bool vis[N][N];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			cin >> a[i][j];
		}
	}

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) left[i][j] = a[i][j] == '1' ? left[i][j - 1] + 1 : 0;
		for (int j = m; j >= 1; --j) right[i][j] = a[i][j] == '1' ? right[i][j + 1] + 1 : 0;
	}

	for (int j = 1; j <= m; ++j) {
		for (int i = 1; i <= n; ++i) up[i][j] = a[i][j] == '1' ? up[i - 1][j] + 1 : 0;
		for (int i = n; i >= 1; --i) down[i][j] = a[i][j] == '1' ? down[i + 1][j] + 1 : 0;
	}

	nrow = n, ncol = m;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) if (a[i][j] == '1' && !vis[i][j]) {
			vis[i][j] = 1;
			queue < pair<int,int> > q;
			q.push({i, j});

			while(!q.empty()) {
				int x = q.front().first, y = q.front().second; q.pop();
				nrow = min(nrow, up[x][y] + down[x][y] - 1);
				ncol = min(ncol, left[x][y] + right[x][y] - 1);
				for (int dir = 0; dir < 4; ++dir) {
					int nx = x + dx[dir];
					int ny = y + dy[dir];
					if (nx < 1 || nx > n || ny < 1 || ny > m || a[nx][ny] == '0' || vis[nx][ny]) continue;
					vis[nx][ny] = 1;
					q.push({nx, ny});
				}
			}
		}
	}

	printf("%d\n", nrow * ncol);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 868 KB Output is correct
3 Correct 44 ms 52944 KB Output is correct
4 Correct 46 ms 53056 KB Output is correct
5 Correct 2 ms 53056 KB Output is correct
6 Correct 2 ms 53056 KB Output is correct
7 Correct 2 ms 53056 KB Output is correct
8 Incorrect 2 ms 53056 KB Output isn't correct
9 Incorrect 2 ms 53056 KB Output isn't correct
10 Incorrect 3 ms 53056 KB Output isn't correct
11 Incorrect 2 ms 53056 KB Output isn't correct
12 Incorrect 2 ms 53056 KB Output isn't correct
13 Correct 2 ms 53056 KB Output is correct
14 Correct 2 ms 53056 KB Output is correct
15 Incorrect 2 ms 53056 KB Output isn't correct
16 Correct 2 ms 53056 KB Output is correct
17 Correct 3 ms 53056 KB Output is correct
18 Incorrect 3 ms 53056 KB Output isn't correct
19 Incorrect 3 ms 53056 KB Output isn't correct
20 Incorrect 5 ms 53056 KB Output isn't correct
21 Incorrect 2 ms 53056 KB Output isn't correct
22 Incorrect 3 ms 53056 KB Output isn't correct
23 Incorrect 4 ms 53056 KB Output isn't correct
24 Incorrect 3 ms 53056 KB Output isn't correct
25 Incorrect 4 ms 53056 KB Output isn't correct
26 Correct 4 ms 53056 KB Output is correct
27 Correct 13 ms 53056 KB Output is correct
28 Incorrect 11 ms 53056 KB Output isn't correct
29 Incorrect 17 ms 53056 KB Output isn't correct
30 Incorrect 22 ms 53056 KB Output isn't correct
31 Incorrect 13 ms 53056 KB Output isn't correct
32 Incorrect 15 ms 53056 KB Output isn't correct
33 Incorrect 19 ms 53056 KB Output isn't correct
34 Incorrect 9 ms 53056 KB Output isn't correct
35 Incorrect 20 ms 53056 KB Output isn't correct
36 Correct 28 ms 53056 KB Output is correct
37 Incorrect 2 ms 53056 KB Output isn't correct
38 Execution timed out 1016 ms 118944 KB Time limit exceeded
39 Incorrect 2 ms 118944 KB Output isn't correct
40 Incorrect 107 ms 118944 KB Output isn't correct
41 Incorrect 2 ms 118944 KB Output isn't correct
42 Incorrect 4 ms 118944 KB Output isn't correct
43 Correct 799 ms 125916 KB Output is correct
44 Incorrect 24 ms 125916 KB Output isn't correct
45 Incorrect 751 ms 131072 KB Output isn't correct
46 Correct 599 ms 131072 KB Output is correct
47 Incorrect 783 ms 131072 KB Output isn't correct
48 Incorrect 696 ms 131072 KB Output isn't correct
49 Correct 945 ms 131072 KB Output is correct
50 Incorrect 732 ms 131072 KB Output isn't correct
51 Incorrect 744 ms 131072 KB Output isn't correct
52 Incorrect 740 ms 131072 KB Output isn't correct
53 Incorrect 728 ms 131072 KB Output isn't correct
54 Incorrect 571 ms 131072 KB Output isn't correct
55 Incorrect 556 ms 131072 KB Output isn't correct
56 Correct 764 ms 131072 KB Output is correct
57 Incorrect 579 ms 131072 KB Output isn't correct
58 Incorrect 586 ms 131072 KB Output isn't correct
59 Incorrect 560 ms 131072 KB Output isn't correct
60 Correct 678 ms 131072 KB Output is correct
61 Correct 930 ms 131072 KB Output is correct
62 Correct 963 ms 131072 KB Output is correct
63 Correct 954 ms 131072 KB Output is correct
64 Correct 565 ms 131072 KB Output is correct
65 Incorrect 715 ms 131072 KB Output isn't correct
66 Incorrect 701 ms 131072 KB Output isn't correct
67 Incorrect 747 ms 131072 KB Output isn't correct
68 Incorrect 764 ms 131072 KB Output isn't correct
69 Incorrect 556 ms 131072 KB Output isn't correct
70 Incorrect 292 ms 131072 KB Output isn't correct
71 Incorrect 494 ms 131072 KB Output isn't correct
72 Incorrect 529 ms 131072 KB Output isn't correct
73 Incorrect 550 ms 131072 KB Output isn't correct
74 Incorrect 539 ms 131072 KB Output isn't correct
75 Incorrect 551 ms 131072 KB Output isn't correct
76 Incorrect 559 ms 131072 KB Output isn't correct
77 Incorrect 579 ms 131072 KB Output isn't correct
78 Incorrect 588 ms 131072 KB Output isn't correct
79 Incorrect 430 ms 131072 KB Output isn't correct
80 Incorrect 422 ms 131072 KB Output isn't correct
81 Incorrect 432 ms 131072 KB Output isn't correct
82 Incorrect 581 ms 131072 KB Output isn't correct
83 Incorrect 579 ms 131072 KB Output isn't correct
84 Incorrect 408 ms 131072 KB Output isn't correct
85 Incorrect 587 ms 131072 KB Output isn't correct
86 Incorrect 902 ms 131072 KB Output isn't correct
87 Incorrect 551 ms 131072 KB Output isn't correct
88 Incorrect 584 ms 131072 KB Output isn't correct
89 Incorrect 658 ms 131072 KB Output isn't correct
90 Incorrect 376 ms 131072 KB Output isn't correct
91 Incorrect 624 ms 131072 KB Output isn't correct
92 Incorrect 677 ms 131072 KB Output isn't correct
93 Incorrect 878 ms 131072 KB Output isn't correct
94 Incorrect 678 ms 131072 KB Output isn't correct
95 Incorrect 586 ms 131072 KB Output isn't correct
96 Incorrect 568 ms 131072 KB Output isn't correct
97 Incorrect 889 ms 131072 KB Output isn't correct
98 Incorrect 566 ms 131072 KB Output isn't correct
99 Incorrect 649 ms 131072 KB Output isn't correct
100 Incorrect 856 ms 131072 KB Output isn't correct