Submission #26311

# Submission time Handle Problem Language Result Execution time Memory
26311 2017-06-29T07:02:13 Z 까제비(#1110) Raspad (COI17_raspad) C++14
100 / 100
1449 ms 142788 KB
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 1e5 + 100, MAX_M = 60;

int N, M, Nr[MAX_N][MAX_M];
int Sum[MAX_N*2][MAX_M*2]; bool Chk[MAX_N*2][MAX_M*2];
int main() {
	cin >> N >> M;
	REPO(i, N) REPO(j, M) scanf("%1d", &Nr[i][j]);
	REPO(i, N) REPO(j, M) {
		if(Nr[i][j] == 1) Sum[i*2][j*2]++;
		if(j && Nr[i][j] && Nr[i][j-1]) Sum[i*2][j*2-1]--;
		if(i && Nr[i][j] && Nr[i-1][j]) Sum[i*2-1][j*2]--;
	}
	queue<pi> Q; Q.push(pi(0, 0)); Chk[0][0] = true;
	while(!Q.empty()) {
		int x, y; tie(x, y) = Q.front(); Q.pop();
		for(int k=0; k<4; k++) {
			int nx = x + "1012"[k] - '1', ny = y + "0121"[k] - '1';
			if(nx < 0 || ny < 0 || nx > 2*N+1 || ny > 2*M+1) continue;
			if(Sum[nx][ny] != 0) continue;
			if(Chk[nx][ny]) continue;
			Chk[nx][ny] = true;
			Q.push(pi(nx, ny));
		}
	}
	ll plusV = 0;
	REPO(i, 2*N) REPO(j, 2*M) {
		if(Sum[i][j] != 0) continue;
		if(Chk[i][j]) continue;
		Q.push(pi(i, j)); Chk[i][j] = true;
		int maxX = -1, minX = 2*N+1;
		while(!Q.empty()) {
			int x, y; tie(x, y) = Q.front(); Q.pop();
			maxX = max(maxX, x);
			minX = min(minX, x);
			for(int k=0; k<4; k++) {
				int nx = x + "1012"[k] - '1', ny = y + "0121"[k] - '1';
				if(nx < 0 || ny < 0 || nx > 2*N || ny > 2*M) continue;
				if(Sum[nx][ny] != 0) continue;
				if(Chk[nx][ny]) continue;
				Chk[nx][ny] = true;
				Q.push(pi(nx, ny));
			}
		}
		plusV += 1ll * (minX / 2) * (N - maxX / 2);
	}
	REPO(i, 2*N) REPO(j, 2*M) {
//		printf("%2d ", Sum[i][j]); if(j == 2*M) puts("");
		if(i) Sum[i][j] += Sum[i-1][j];
		if(j) Sum[i][j] += Sum[i][j-1];
		if(i && j) Sum[i][j] -= Sum[i-1][j-1];
	}

	ll ans = 0;
//	for(int i=1; i<=N; i++) for(int j=i; j<=N; j++)
//		ans += (Sum[2*j][2*M] - Sum[2*i-1][2*M]);
	for(int j=1; j<=N; j++)
		ans += 1ll * j * Sum[2*j][2*M];
	for(int i=1; i<=N; i++)
		ans -= 1ll * (N-i+1) * Sum[2*i-1][2*M];
	printf("%lld\n", ans + plusV);
	return 0;
}

Compilation message

raspad.cpp: In function 'int main()':
raspad.cpp:22:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  REPO(i, N) REPO(j, M) scanf("%1d", &Nr[i][j]);
                                               ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 142788 KB Output is correct
2 Correct 0 ms 142788 KB Output is correct
3 Correct 0 ms 142788 KB Output is correct
4 Correct 0 ms 142788 KB Output is correct
5 Correct 0 ms 142788 KB Output is correct
6 Correct 0 ms 142788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 142788 KB Output is correct
2 Correct 0 ms 142788 KB Output is correct
3 Correct 0 ms 142788 KB Output is correct
4 Correct 0 ms 142788 KB Output is correct
5 Correct 0 ms 142788 KB Output is correct
6 Correct 0 ms 142788 KB Output is correct
7 Correct 16 ms 142788 KB Output is correct
8 Correct 0 ms 142788 KB Output is correct
9 Correct 9 ms 142788 KB Output is correct
10 Correct 9 ms 142788 KB Output is correct
11 Correct 9 ms 142788 KB Output is correct
12 Correct 9 ms 142788 KB Output is correct
13 Correct 9 ms 142788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 142788 KB Output is correct
2 Correct 456 ms 142788 KB Output is correct
3 Correct 443 ms 142788 KB Output is correct
4 Correct 389 ms 142788 KB Output is correct
5 Correct 119 ms 142788 KB Output is correct
6 Correct 463 ms 142788 KB Output is correct
7 Correct 453 ms 142788 KB Output is correct
8 Correct 369 ms 142788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 142788 KB Output is correct
2 Correct 0 ms 142788 KB Output is correct
3 Correct 0 ms 142788 KB Output is correct
4 Correct 0 ms 142788 KB Output is correct
5 Correct 0 ms 142788 KB Output is correct
6 Correct 0 ms 142788 KB Output is correct
7 Correct 16 ms 142788 KB Output is correct
8 Correct 0 ms 142788 KB Output is correct
9 Correct 9 ms 142788 KB Output is correct
10 Correct 9 ms 142788 KB Output is correct
11 Correct 9 ms 142788 KB Output is correct
12 Correct 9 ms 142788 KB Output is correct
13 Correct 9 ms 142788 KB Output is correct
14 Correct 139 ms 142788 KB Output is correct
15 Correct 456 ms 142788 KB Output is correct
16 Correct 443 ms 142788 KB Output is correct
17 Correct 389 ms 142788 KB Output is correct
18 Correct 119 ms 142788 KB Output is correct
19 Correct 463 ms 142788 KB Output is correct
20 Correct 453 ms 142788 KB Output is correct
21 Correct 369 ms 142788 KB Output is correct
22 Correct 929 ms 142788 KB Output is correct
23 Correct 1449 ms 142788 KB Output is correct
24 Correct 1229 ms 142788 KB Output is correct
25 Correct 1326 ms 142788 KB Output is correct
26 Correct 1239 ms 142788 KB Output is correct
27 Correct 1069 ms 142788 KB Output is correct
28 Correct 1156 ms 142788 KB Output is correct
29 Correct 1343 ms 142788 KB Output is correct
30 Correct 1209 ms 142788 KB Output is correct
31 Correct 1159 ms 142788 KB Output is correct
32 Correct 1259 ms 142788 KB Output is correct
33 Correct 1193 ms 142788 KB Output is correct
34 Correct 1229 ms 142788 KB Output is correct