답안 #15965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
15965 2015-08-02T18:00:41 Z myungwoo 경찰관과 강도 (BOI14_coprobber) C++14
0 / 100
56 ms 23956 KB
#include <bits/stdc++.h>
using namespace std;

#define MAXK 500005
#define pb push_back
#define sz(v) ((int)(v).size())

static int N, K, cop_pos;
static int num[501][501][2], deg[MAXK];
static int C[MAXK], R[MAXK], T[MAXK], F[MAXK];
static bool w[501][501], V[MAXK];
static vector<int> con[MAXK], rcon[MAXK];

inline int get_dp(int c, int r, int t)
{
	int n = num[c][r][t];
	if (!V[n]) return 0;
	if (!t) return C[F[n]];
	return 1;
}

int start(int n, bool A[500][500])
{
	N = n;
	for (int i=1;i<=N;i++) for (int j=1;j<=N;j++) w[i][j] = A[i-1][j-1];
	for (int i=1;i<=N;i++) for (int j=1;j<=N;j++) for (int k=0;k<2;k++){
		num[i][j][k] = ++K;
		C[K] = i, R[K] = j, T[K] = k;
	}
	for (int i=1;i<=N;i++) for (int j=1;j<=N;j++) for (int k=0;k<2;k++){
		int a = num[i][j][k];
		if (!k){
			int b = num[i][j][!k];
			con[a].pb(b); rcon[b].pb(a);
		}
		for (int t=1;t<=N;t++){
			if (!k && w[i][t]){
				int b = num[t][j][!k];
				con[a].pb(b); rcon[b].pb(a);
			}
			if (k && w[j][t]){
				int b = num[i][t][!k];
				con[a].pb(b); rcon[b].pb(a);
			}
		}
	}
	for (int i=1;i<=K;i++) deg[i] = sz(con[i]);
	queue <int> que;
	for (int i=1;i<=N;i++){
		V[num[i][i][0]] = 1, que.push(num[i][i][0]);
		V[num[i][i][1]] = 1, que.push(num[i][i][1]);
	}
	while (!que.empty()){
		int q = que.front(); que.pop();
		int c = C[q], r = R[q], t = T[q];
		if (t){
			for (int k: rcon[q]){
				if (!V[k]) V[k] = 1, F[k] = q, que.push(k);
			}
		}else{
			for (int k: rcon[q]){
				if (!--deg[k]) V[k] = 1, que.push(k);
			}
		}
	}
	for (int i=1;i<=N;i++){
		bool sw = 0;
		for (int j=1;j<=N;j++) if (!get_dp(i, j, 1)){ sw = 1; break; }
		if (sw) continue;
//		printf("Cop start at %d\n", i);
		cop_pos = i;
		return i-1;
	}
    return -1;
}

int nextMove(int x)
{
	++x;
	int to = get_dp(cop_pos, x, 0);
//	printf("Robber moved to %d\n", x);
//	printf("Then cop move to %d\n", to);
	return to-1;
}

Compilation message

coprobber.cpp: In function 'int start(int, bool (*)[500])':
coprobber.cpp:55:7: warning: unused variable 'c' [-Wunused-variable]
   int c = C[q], r = R[q], t = T[q];
       ^
coprobber.cpp:55:17: warning: unused variable 'r' [-Wunused-variable]
   int c = C[q], r = R[q], t = T[q];
                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23840 KB Output is correct
2 Correct 23 ms 23936 KB Output is correct
3 Incorrect 23 ms 23956 KB the situation repeated
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23936 KB Output is correct
2 Incorrect 23 ms 23904 KB the situation repeated
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23840 KB Output is correct
2 Correct 56 ms 23852 KB Output is correct
3 Incorrect 23 ms 23936 KB the situation repeated
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23820 KB Output is correct
3 Incorrect 23 ms 23936 KB the situation repeated
4 Halted 0 ms 0 KB -