제출 #72144

#제출 시각아이디문제언어결과실행 시간메모리
72144BOJ 8481 (#118)마법 다우징 (FXCUP3_magic)C++17
100 / 100
3 ms376 KiB
#include "dowsing.h" #include <cstdlib> using namespace std; void FindTreasure(int N) { int a[2], idx=0; int v[50]={0}; for(int i=1;i<=N;i++){ if(Detect(i,i)==1) a[idx++]=i; } if(idx==0){ int tmp; if(N%2==0){ for(int i=0;i<N/2;i++){ do{ tmp=rand()%(N/2); } while(v[tmp] != 0); if(i==(N/2-1)) break; if(Detect(2*tmp+1,2*tmp+2)==1) break; v[tmp]=1; } int j=(tmp==0?3:1); if(Detect(2*tmp+1,j)==1) Report(2*tmp+1,2*tmp+1); else Report(2*tmp+2,2*tmp+2); } else{ for(int i=0;i<(N+1)/2;i++){ do{ tmp=rand()%(N/2); } while(v[tmp] != 0); if(i==(N-1)/2) break; if(tmp!=(N-1)/2){ if(Detect(2*tmp+1,2*tmp+2)==1) break; } else{ if(Detect(2*tmp,2*tmp+1)==1) break; } v[tmp]=1; } int j=(tmp==0?3:1); if(tmp!=(N-1)/2){ if(Detect(2*tmp+1,j)==1) Report(2*tmp+1,2*tmp+1); else Report(2*tmp+2,2*tmp+2); } else{ if(Detect(2*tmp,j)==1) Report(2*tmp,2*tmp); else Report(2*tmp+1,2*tmp+1); } } } else{ int i; for(i=1;i==a[0]||i==a[1];i++); if(Detect(a[0],i) == 1) Report(a[0],a[1]); else Report(a[1],a[0]); } }

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

dowsing.cpp: In function 'void FindTreasure(int)':
dowsing.cpp:12:7: warning: 'tmp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int tmp;
       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...