제출 #284638

#제출 시각아이디문제언어결과실행 시간메모리
284638triplem5ds동굴 (IOI13_cave)C++14
100 / 100
1035 ms752 KiB
#include "cave.h"
#include "bits/stdc++.h"
using namespace std;
int W[5005];
int ans[5005];
int S[5005];
void exploreCave(int N) {
  memset(ans, -1, sizeof ans);
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++)if(ans[j] == -1)S[j] = 0;
    else S[j] = ans[j];
    int x = tryCombination(S);
    if(x == -1)x = N;
    bool f = (x <= i);  ///the door is closed then it should be open by the other state
    ///find which switch is it
    int lo  = 0, hi = N - 1 - i;
    while(lo < hi){
      int md = lo + (hi - lo) / 2;
      int cnt = 0;
      for(int j = 0; j < N; j++){
        if(ans[j] != -1)S[j] = ans[j];
        else {
          S[j] = (f ^ (cnt > md));
          cnt++;
        }
      }
      int x = tryCombination(S);
      if(x == -1)x = N;
      if(x > i)
        hi = md;
      else
        lo = md + 1;
    }
    int cnt = 0;
    for(int j = 0; j < N; j++){
      if(ans[j] == -1){
        if(cnt == lo){
          ans[j]=f;
          W[j] = i;
          break;
        }
        cnt++;
      }
    }
  }
  answer(ans,W);
}
#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...