제출 #38544

#제출 시각아이디문제언어결과실행 시간메모리
38544WaschbarCop and Robber (BOI14_coprobber)C++14
16 / 100
45 ms2424 KiB
#include <bits/stdc++.h>
#include "coprobber.h"
//using namespace std;

//const int MAX_N = 15;
int n, nn, mm, s, timer, tp, tpp;
int p[1000], tin[1000], tout[1000];
bool ind;
bool g[1000][1000];
bool used[1000];

void DFS(int f, int pr) {
		p[f] = pr;
		tin[f] = ++timer;
		used[f] = 1;
		
		for(int i = 0; i < n; i++) {
			if(!g[f][i] || i == pr) continue;
			if(used[i]) { ind = 1; continue;}
			DFS(i,f);
		}	
		
		tout[f] = timer;
}

bool upper(int x, int y) {
	//cout << x << " - " << tin[x] << " " << tout[x] << " | " << y << " - " << tin[y] << " " << tout[y] << endl;
	return ((tin[x] <= tin[y]) && (tout[x] >= tout[y]));
}

int start(int N, bool A[MAX_N][MAX_N]) {
    n = N; s = 0;
    for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++)
    	g[i][j] = A[i][j];
    	
    DFS(0, -1);
    
    if(!ind) tp = 1;
    else tp = 2;
    
    if(tp == 1)
		return 0;
	if(tp == 2) {
		//return -1;
		mm = 0;
		while(g[mm][mm+1])
			mm++;
		nn = n/mm;
		if(nn > 4 || mm > 4) return -1;
		if(nn == 2 && mm == 2) {tpp = 1; s=0; return 0;}
		if(nn == 2 && mm == 3) {tpp = 2; s=1; return 1;}
		if(nn == 3 && mm == 2) {tpp = 3; s=2; return 2;}
		if(nn == 3 && mm == 3) {tpp = 4; s=4; return 4;}
		if(nn == 3 && mm == 4) {tpp = 5; s=5; return s;}
		if(nn == 4 && mm == 3) {tpp = 6; s=3; return s;}
		//if(nn == 4 && mm = 4) {tpp = 7; s=0; return s;}
		return -1;
	}
}

int nextMove(int R) {
	if(tp == 1){
    	for(int i = 0; i < n; i++) {
    		//cout << s << " " << i << " " << g[s][i] << endl;
    		if(!g[s][i] || i == p[s]) continue;
    		if(upper(i,R)) {s = i; return i;}
		}
			return -1;
	}
	if(tp == 2) {
		if(tpp == 1) {
			if(R == 1 || R == 2) return R;
			return 0;
		}
		if(tpp == 2) {
			if(R == 3 || R == 5) return 1;
			return R;
		}
		if(tpp == 3) {
			if(R == 1 || R == 5) return 2;
			return R;
		}
		if(tpp == 4) {
			if(g[s][R]) return R;
			return s;
		}
		if(tpp == 5) {
			if(g[s][R]) return R;
			if(R == 3 || R == 7 || R == 11) s=6;
			return s;
		}
		if(tpp == 6) {
			if(g[s][R]) return R;
			if(R == 9 || R == 10 || R == 11) s=6;
			return s;
		}
		if(tpp == 7) {
			
		}
	}
}
/*
bool v[MAX_N][MAX_N];

int main() {
	
	int nn;
	cin >> nn;
	
	for(int i = 1; i < nn; i++) {
		int x, y;
		cin >> x >> y;
		v[x][y] = v[y][x] = 1;
	}
	
	cout << ":: " << start(nn,v) << endl;
	
	while(true){
		int x;
		cin >> x;
		cout <<":: " << nextMove(x) << endl;
	}
	
}*/

컴파일 시 표준 에러 (stderr) 메시지

coprobber.cpp: In function 'int start(int, bool (*)[500])':
coprobber.cpp:60:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
coprobber.cpp: In function 'int nextMove(int)':
coprobber.cpp:102:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...