Submission #26351

# Submission time Handle Problem Language Result Execution time Memory
26351 2017-06-29T10:00:29 Z kajebiii Raspad (COI17_raspad) C++14
0 / 100
453 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 Incorrect 0 ms 142788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 142788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 453 ms 142788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 142788 KB Output isn't correct
2 Halted 0 ms 0 KB -