제출 #539166

#제출 시각아이디문제언어결과실행 시간메모리
539166astoria동굴 (IOI13_cave)C++14
100 / 100
874 ms468 KiB
#include "cave.h" #include <bits/stdc++.h> using namespace std; int n; int finalval[5005]; int f(int m){ int s[n]; int counter=0; int secct=0; for (int i=0; i<n; i++){ if (finalval[i] != -1){ s[i] = finalval[i]; secct++; } else{ if (counter < m){ counter++; s[i] = 0; } else { s[i] = 1; } } } int x = tryCombination(s); if (x>secct || x==-1) return 1; else return 0; } int g(int m){ int s[n]; int counter=0; int secct=0; for (int i=0; i<n; i++){ if (finalval[i] != -1){ s[i] = finalval[i]; secct++; } else{ if (counter < m){ counter++; s[i] = 1; } else { s[i] = 0; } } } int x = tryCombination(s); if (x>secct || x==-1) return 1; else return 0; } int bs0(int ct){ int l=1, r=n-ct; while (l<r){ int m=(l+r)/2; if (f(m)) r=m; else l=m+1; } int pos; int coolcounter=0; for (int i=0; i<n; i++){ if (finalval[i] == -1) coolcounter++; if (coolcounter == l){ pos = i; break; } } return pos; } int bs1(int ct){ int l=1, r=n-ct; while (l<r){ int m=(l+r)/2; if (g(m)) r=m; else l=m+1; } int pos; int coolcounter=0; for (int i=0; i<n; i++){ if (finalval[i] == -1) coolcounter++; if (coolcounter == l){ pos = i; break; } } return pos; } void exploreCave(int N) { n = N; //cout << n; memset(finalval, -1, sizeof(finalval)); int D[N]; memset(D, -1, sizeof(D)); for (int c=0; c<N; c++){ int S[N]; for (int j=0; j<N; j++){ if (finalval[j] != -1) S[j] = finalval[j]; else S[j] = 0; } int x = tryCombination(S); int ele; if (x>c || x==-1) ele = bs0(c); else ele = bs1(c); D[ele] = c; if (x>c || x==-1) finalval[ele] = 0; else finalval[ele] = 1; //cout << ele << "\n"; } answer(finalval, D); }

컴파일 시 표준 에러 (stderr) 메시지

cave.cpp: In function 'int bs0(int)':
cave.cpp:72:12: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   72 |     return pos;
      |            ^~~
cave.cpp: In function 'int bs1(int)':
cave.cpp:91:12: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   91 |     return pos;
      |            ^~~
#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...