제출 #883464

#제출 시각아이디문제언어결과실행 시간메모리
883464theghostking동굴 (IOI13_cave)C++17
100 / 100
274 ms856 KiB
#include "cave.h"

void exploreCave(int N) {
    /* ... */
	int sw[N]; //sw[i] -> orientation of ith switch
	int dw[N]; //dw[i] -> door that switch i is connected to
	for (int i = 0; i<N; i++){
	    sw[i] = 0;
	    dw[i] = -1;
	}
	for (int k = 0; k<N; k++){
	    //find switch to kth door
	    for (int i = 0; i<N; i++){
	        if (dw[i] == -1){
	            sw[i] = 0;
	        }
	    }
	    int res = tryCombination(sw);
	    int ori = 1;
	    if (res > k || res == -1){
	        ori = 0;
	    }
	    //now find range
	    int lo = 0;
	    int hi = N-1;
	    int mid;
	    int ind;
	    while (lo <= hi){
	        if (lo == hi){
	            ind = lo;
	            break;
	        }
	        mid = (lo + hi)/2;
	        //check lo...mid
	        for (int i = lo; i<=mid; i++){
	            if (dw[i] == -1){
	                sw[i] = ori;
	            }
	        }
	        for (int i = mid+1; i<=hi; i++){
	            if (dw[i] == -1){
	                sw[i] = 1-ori;
	            }
	        }
	        res = tryCombination(sw);
	        if (res > k || res == -1){
	            //in this range
	            ind = lo;
	            hi = mid;
	        }
	        else{
	            lo = mid + 1;
	        }
	    }
	    dw[ind] = k;
	    sw[ind] = ori;
	}
	answer(sw,dw);
}

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

cave.cpp: In function 'void exploreCave(int)':
cave.cpp:56:14: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   56 |      sw[ind] = ori;
      |      ~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...