Submission #26358

# Submission time Handle Problem Language Result Execution time Memory
26358 2017-06-29T10:18:03 Z kdh9949 Raspad (COI17_raspad) C++14
100 / 100
743 ms 353704 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m, mx, Mx, e[100010][55][4], vis[100010][55], ts;
char b[100010][55];
ll ans;

void ff(int x, int y){
	if(x < 0 || y < 0 || x > n || y > m || vis[x][y]) return;
	vis[x][y] = 1;
	mx = min(mx, x); Mx = max(Mx, x);
	for(int i = 0; i < 4; i++) if(!e[x][y][i]) ff(x + dx[i], y + dy[i]);
}

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%s", b[i] + 1);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			b[i][j] -= '0';
			if(b[i][j]) ans += 1LL * i * (n + 1 - i);
			if(b[i][j] && b[i - 1][j]) ans -= 1LL * (i - 1) * (n + 1 - i);
			if(b[i][j] && b[i][j - 1]) ans -= 1LL * i * (n + 1 - i);
		}
	}
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= m; j++){
			e[i][j][0] = b[i + 1][j] && b[i + 1][j + 1];
			e[i][j][1] = b[i][j + 1] && b[i + 1][j + 1];
			e[i][j][2] = b[i][j] && b[i][j + 1];
			e[i][j][3] = b[i][j] && b[i + 1][j];
		}
	}
	ff(0, 0);
	for(int i = 1; i < n; i++){
		for(int j = 1; j < m; j++){
			if(!vis[i][j]){
				mx = n; Mx = 0;
				ff(i, j);
				ans += 1LL * mx * (n - Mx);
			}
		}
	}
	printf("%lld\n", ans);
}

Compilation message

raspad.cpp: In function 'int main()':
raspad.cpp:18:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
raspad.cpp:19:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%s", b[i] + 1);
                                                   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 114824 KB Output is correct
2 Correct 0 ms 114824 KB Output is correct
3 Correct 0 ms 114824 KB Output is correct
4 Correct 0 ms 114824 KB Output is correct
5 Correct 0 ms 114824 KB Output is correct
6 Correct 0 ms 114824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 114824 KB Output is correct
2 Correct 0 ms 114824 KB Output is correct
3 Correct 0 ms 114824 KB Output is correct
4 Correct 0 ms 114824 KB Output is correct
5 Correct 0 ms 114824 KB Output is correct
6 Correct 0 ms 114824 KB Output is correct
7 Correct 0 ms 116232 KB Output is correct
8 Correct 0 ms 114824 KB Output is correct
9 Correct 3 ms 114824 KB Output is correct
10 Correct 0 ms 115620 KB Output is correct
11 Correct 3 ms 115140 KB Output is correct
12 Correct 0 ms 114824 KB Output is correct
13 Correct 3 ms 114824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 119388 KB Output is correct
2 Correct 149 ms 128064 KB Output is correct
3 Correct 149 ms 124076 KB Output is correct
4 Correct 233 ms 182200 KB Output is correct
5 Correct 43 ms 117532 KB Output is correct
6 Correct 143 ms 124092 KB Output is correct
7 Correct 96 ms 124080 KB Output is correct
8 Correct 99 ms 122208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 114824 KB Output is correct
2 Correct 0 ms 114824 KB Output is correct
3 Correct 0 ms 114824 KB Output is correct
4 Correct 0 ms 114824 KB Output is correct
5 Correct 0 ms 114824 KB Output is correct
6 Correct 0 ms 114824 KB Output is correct
7 Correct 0 ms 116232 KB Output is correct
8 Correct 0 ms 114824 KB Output is correct
9 Correct 3 ms 114824 KB Output is correct
10 Correct 0 ms 115620 KB Output is correct
11 Correct 3 ms 115140 KB Output is correct
12 Correct 0 ms 114824 KB Output is correct
13 Correct 3 ms 114824 KB Output is correct
14 Correct 33 ms 119388 KB Output is correct
15 Correct 149 ms 128064 KB Output is correct
16 Correct 149 ms 124076 KB Output is correct
17 Correct 233 ms 182200 KB Output is correct
18 Correct 43 ms 117532 KB Output is correct
19 Correct 143 ms 124092 KB Output is correct
20 Correct 96 ms 124080 KB Output is correct
21 Correct 99 ms 122208 KB Output is correct
22 Correct 273 ms 134600 KB Output is correct
23 Correct 339 ms 124080 KB Output is correct
24 Correct 293 ms 124080 KB Output is correct
25 Correct 383 ms 157016 KB Output is correct
26 Correct 743 ms 236576 KB Output is correct
27 Correct 296 ms 124496 KB Output is correct
28 Correct 326 ms 124084 KB Output is correct
29 Correct 399 ms 142736 KB Output is correct
30 Correct 699 ms 349020 KB Output is correct
31 Correct 646 ms 353704 KB Output is correct
32 Correct 266 ms 124136 KB Output is correct
33 Correct 243 ms 123160 KB Output is correct
34 Correct 273 ms 123260 KB Output is correct