답안 #72108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72108 2018-08-26T05:19:25 Z BOJ 8481(#2179, veydpz, jh05013, 16silver) 마법 다우징 (FXCUP3_magic) C++17
0 / 100
1000 ms 380 KB
#include "dowsing.h"
#include <cstdlib>
using namespace std;

void FindTreasure(int N) {
	int a[2], idx=0;
	int m[101];
	int v[101]={0};
	int tmp;
	for(int i=0;i<N*9+7;i++) rand();
	for(int i=1;i<=N;i++){
		do{
			tmp=rand()%N;
		} while(v[tmp] != 0);
		m[i]=tmp+1;
		v[tmp]=1;
	}
	for(int i=1;i<=N;i++){
		if(Detect(i,m[i])==1) a[idx++]=i;
	}
	for(int i=0;i<=N;i++) v[i]=0;
	if(idx==0){
		if(N%2==0){
			for(int i=0;i<N/2;i++){
				do{
					tmp=rand()%(N/2);
				} while(v[tmp] != 0);
				if(Detect(2*tmp+1,m[2*tmp+2])==1) break;
				v[tmp]=1;
			}
			int j=(tmp==0?3:1);
			if(Detect(2*tmp+1,m[j])==1) Report(2*tmp+1,m[2*tmp+1]);
			else Report(2*tmp+2,m[2*tmp+2]);
		}
		else{
			for(int i=0;i<(N+1)/2;i++){
				do{
					tmp=rand()%(N/2);
				} while(v[tmp] != 0);
				if(tmp!=(N-1)/2){
					if(Detect(2*tmp+1,m[2*tmp+2])==1) break;
				}
				else{
					if(Detect(2*tmp,m[2*tmp+1])==1) break;
				}
				v[tmp]=1;
			}
			int j=(tmp==0?3:1);
			if(tmp!=(N-1)/2){
				if(Detect(2*tmp+1,m[j])==1) Report(2*tmp+1,m[2*tmp+1]);
				else Report(2*tmp+2,m[2*tmp+2]);
			}
			else{
				if(Detect(2*tmp,m[j])==1) Report(2*tmp,m[2*tmp]);
				else Report(2*tmp+1,m[2*tmp+1]);
			}

		}
	}
	else{
		int i;
		for(i=1;i==a[0]||i==a[1];i++);
		if(Detect(a[0],m[i]) == 1) Report(a[0],m[a[1]]);
		else Report(a[1],m[a[0]]);
	}
}

Compilation message

dowsing.cpp: In function 'void FindTreasure(int)':
dowsing.cpp:9:6: warning: 'tmp' may be used uninitialized in this function [-Wmaybe-uninitialized]
  int tmp;
      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Correct : C = 5
2 Correct 2 ms 376 KB Correct : C = 5
3 Correct 3 ms 380 KB Correct : C = 149
4 Correct 3 ms 376 KB Correct : C = 149
5 Partially correct 3 ms 376 KB Partially correct : C = 151
6 Partially correct 3 ms 376 KB Partially correct : C = 151
7 Execution timed out 1066 ms 380 KB Time limit exceeded
8 Halted 0 ms 0 KB -