Submission #857522

#TimeUsernameProblemLanguageResultExecution timeMemory
857522chilinhxyzabcCave (IOI13_cave)C++17
0 / 100
7 ms348 KiB
#include <bits/stdc++.h>
#include "cave.h"
using namespace std; 

void exploreCave(int n) {
    int s[n], d[n];
    for(int i = 0; i < n; i++) {
        s[i] = 0;
        d[i] = -1;
    }
    for(int i = 0; i < n; i++) {
        int curDoor = tryCombination(s);
        if(curDoor == -1)
            break;
        else {
            int l = i, r = n - 1, res;
            while(l <= r) {
                int m = (l + r) / 2;
                s[m] = 1 - s[m];
                int door = tryCombination(s);
                if(curDoor == door) {
                    r = m - 1;
                } else {
                    l = m + 1;
                    res = m;
                }
                s[m] = 1 - s[m];
            }
            d[res] = curDoor;
            s[res] = 1 - s[res];
            for(int j = i; j < res; j++) {
                s[j] = 1 - s[j];
                int door = tryCombination(s);
                s[j] = 1 - s[j];
                d[j] = door;
            }
            i = res;
        }
    }
    answer(s, d);
}

Compilation message (stderr)

cave.cpp: In function 'void exploreCave(int)':
cave.cpp:31:30: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |             for(int j = i; j < res; j++) {
      |                            ~~^~~~~
#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...