제출 #38559

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

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) {
		mm = 0;
		while(g[mm][mm+1])
			mm++;
		mm++;
		nn = n/mm;
		if(nn == 2) {tpp = 1; s=0; return s;}
		else if(mm == 2) {tpp = 2; s=0; return s;}
		else if(nn == 3) {tpp = 3; s=mm; return s;}		
		else if(mm == 3) {tpp = 4; s=1; 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(g[s][R]) return R;
			if(R != s+1 && R != mm+s+1) s++;
			return s;
		}
		if(tpp == 2) {
			if(g[s][R]) return R;
			if(R != s+2 && R != s+3) s+=2;
			return s;
		}
		if(tpp == 3) {
			if(g[s][R]) return R;
			if(R != s+1 && R != s+mm+1 && R != s-mm+1) s++;
			return s;
		}
		if(tpp == 4) {
			if(g[s][R]) return R;
			if(R != s+2 && R != s+3 && R != s+4) s+=3;
			return s;
		}
	}
}

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

coprobber.cpp: In function 'int start(int, bool (*)[500])':
coprobber.cpp:55:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
coprobber.cpp: In function 'int nextMove(int)':
coprobber.cpp:88: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...