제출 #116632

#제출 시각아이디문제언어결과실행 시간메모리
116632roseanne_pcy동굴 (IOI13_cave)C++14
100 / 100
1287 ms684 KiB
#include "cave.h" #include <bits/stdc++.h> using namespace std; #define vi vector<int> #define pb push_back bool solved[5005]; int sol[5005]; int connect[5005]; int arr[5005]; int tmp[5005]; vi cand; void exploreCave(int n) { for(int i = 0; i< n; i++) cand.pb(i); for(int it = 0; it< n-1; it++) { //printf("-----iteration %d\n", it); for(int i = 0; i< n; i++) if(solved[i]) arr[i] = sol[i]; for(int i = 0; i< (int) cand.size(); i++) arr[cand[i]] = 0; int last = tryCombination(arr); if(last == -1) last = 1e9; int L = 0, R = cand.size()-1; memset(tmp, 0, sizeof tmp); while(L< R) { //printf("L = %d and R = %d\n", L, R); int mid = (L+R)/2; for(int i = 0; i< n; i++) if(solved[i]) arr[i] = sol[i]; for(int i = mid+1; i<= R; i++) if(!solved[cand[i]]) arr[cand[i]] = 1-arr[cand[i]]; int x = tryCombination(arr); if(x == -1) x = 1e9; if(x< last) { L = mid+1; last = x; if(L == R) sol[cand[L]] = 1-arr[cand[L]]; } else if(x> last) { L = mid+1; if(L == R) sol[cand[L]] = arr[cand[L]]; for(int i = mid+1; i<= R; i++) if(!solved[cand[i]]) arr[cand[i]] = 1-arr[cand[i]]; } else { int trex = R; R = mid; if(L == R) sol[cand[L]]= 1-arr[cand[L]]; for(int i = mid+1; i<= trex; i++) if(!solved[cand[i]]) arr[cand[i]] = 1-arr[cand[i]]; } } connect[cand[L]] = last; solved[cand[L]] = 1; //printf("connect %d to %d\n", cand[L], last); //printf("position for %d is %d\n", cand[L], sol[cand[L]]); cand.erase(cand.begin()+L); } int pos = cand[0]; //printf("pos is %d\n", pos); memset(arr, 0, sizeof arr); for(int i = 0; i< n; i++) if(solved[i]) arr[i] = sol[i]; int x = tryCombination(arr); int y; if(x == -1) { arr[pos] = 1-arr[pos]; y = tryCombination(arr); sol[pos] = 1-arr[pos]; } else { y = x; sol[pos] = 1-arr[pos]; } connect[pos] = y; answer(sol, connect); }
#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...