답안 #26352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26352 2017-06-29T10:01:32 Z kajebiii Raspad (COI17_raspad) C++14
100 / 100
1363 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]);
                                               ^
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 9 ms 142788 KB Output is correct
8 Correct 0 ms 142788 KB Output is correct
9 Correct 13 ms 142788 KB Output is correct
10 Correct 9 ms 142788 KB Output is correct
11 Correct 13 ms 142788 KB Output is correct
12 Correct 6 ms 142788 KB Output is correct
13 Correct 13 ms 142788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 142788 KB Output is correct
2 Correct 429 ms 142788 KB Output is correct
3 Correct 476 ms 142788 KB Output is correct
4 Correct 393 ms 142788 KB Output is correct
5 Correct 166 ms 142788 KB Output is correct
6 Correct 449 ms 142788 KB Output is correct
7 Correct 429 ms 142788 KB Output is correct
8 Correct 406 ms 142788 KB Output is correct
# 결과 실행 시간 메모리 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 9 ms 142788 KB Output is correct
8 Correct 0 ms 142788 KB Output is correct
9 Correct 13 ms 142788 KB Output is correct
10 Correct 9 ms 142788 KB Output is correct
11 Correct 13 ms 142788 KB Output is correct
12 Correct 6 ms 142788 KB Output is correct
13 Correct 13 ms 142788 KB Output is correct
14 Correct 143 ms 142788 KB Output is correct
15 Correct 429 ms 142788 KB Output is correct
16 Correct 476 ms 142788 KB Output is correct
17 Correct 393 ms 142788 KB Output is correct
18 Correct 166 ms 142788 KB Output is correct
19 Correct 449 ms 142788 KB Output is correct
20 Correct 429 ms 142788 KB Output is correct
21 Correct 406 ms 142788 KB Output is correct
22 Correct 929 ms 142788 KB Output is correct
23 Correct 1349 ms 142788 KB Output is correct
24 Correct 1293 ms 142788 KB Output is correct
25 Correct 1289 ms 142788 KB Output is correct
26 Correct 1209 ms 142788 KB Output is correct
27 Correct 1063 ms 142788 KB Output is correct
28 Correct 1149 ms 142788 KB Output is correct
29 Correct 1363 ms 142788 KB Output is correct
30 Correct 1129 ms 142788 KB Output is correct
31 Correct 1099 ms 142788 KB Output is correct
32 Correct 1219 ms 142788 KB Output is correct
33 Correct 1286 ms 142788 KB Output is correct
34 Correct 1263 ms 142788 KB Output is correct