Submission #151096

#TimeUsernameProblemLanguageResultExecution timeMemory
151096joseacazCave (IOI13_cave)C++17
100 / 100
1192 ms640 KiB
#include "cave.h" #include <bits/stdc++.h> using namespace std; // Main // int tryCombination(int N, int S[]) // void answer(int N, int S[], int D[]) void exploreCave ( int N ) { int s, e, mid, val, res, ans; int aux[N], S[N], D[N]; for ( int i = 0; i < N; i++ ) S[i] = -1, D[i] = -1; for ( int i = 0; i < N; i++ ) { for ( int j = 0; j < N; j++ ) if ( S[j] == -1 ) aux[j] = 0; ans = tryCombination ( aux ); if ( ans == i ) { //the door opens with 1's s = 0, e = N - 1; while ( s <= e ) { mid = (s + e) / 2; for ( int k = 0; k <= mid; k++ ) if ( S[k] == -1 ) aux[k] = 1; for ( int k = mid + 1; k < N; k++ ) if ( S[k] == -1 ) aux[k] = 0; ans = tryCombination ( aux ); val = (ans == i ? 0 : 1 ); if ( val ) res = mid, e = mid - 1; else s = mid + 1; } aux[res] = 1; S[res] = 1; D[res] = i; } else { //the door opens with 0's s = 0, e = N - 1; while ( s <= e ) { mid = (s + e) / 2; for ( int k = 0; k <= mid; k++ ) if ( S[k] == -1 ) aux[k] = 0; for ( int k = mid + 1; k < N; k++ ) if ( S[k] == -1 ) aux[k] = 1; ans = tryCombination ( aux ); val = (ans == i ? 0 : 1 ); if ( val ) res = mid, e = mid - 1; else s = mid + 1; } aux[res] = 0; S[res] = 0; D[res] = i; } } answer ( S, D ); }

Compilation message (stderr)

cave.cpp: In function 'void exploreCave(int)':
cave.cpp:50:13: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
    aux[res] = 1;
    ~~~~~~~~~^~~
#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...