Advertisement
Josif_tepe

Untitled

Aug 23rd, 2023
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include "cave.h"
  2. #include <iostream>
  3. const int maxn = 5050;
  4. int S[maxn], D[maxn];
  5. int switched[maxn];
  6. void exploreCave(int N) {
  7.     for(int i = 0; i < N; i++) {
  8.         int comb = (tryCombination(S) != i);
  9.         int L = 0, R = N - 1;
  10.        
  11.         while(L < R) {
  12.             int mid = (L + R) / 2;
  13.             for(int j = L; j <= mid; j++) {
  14.                 if(!switched[j]) {
  15.                     S[j] = 1 - S[j];
  16.                 }
  17.             }
  18.             int comb2 = (tryCombination(S) != i);
  19.             for(int j = L; j <= mid; j++) {
  20.                 if(!switched[j]) {
  21.                     S[j] = 1 - S[j];
  22.                 }
  23.             }
  24.             if(comb == comb2) {
  25.                 L = mid + 1;
  26.             }
  27.             else {
  28.                 R = mid;
  29.             }
  30.            
  31.         }
  32.         D[L] = i;
  33.         if(comb == 0) {
  34.             S[L] = 1 - S[L];
  35.         }
  36.         switched[L] = 1;
  37.     }
  38.     answer(S, D);
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement