제출 #330485

#제출 시각아이디문제언어결과실행 시간메모리
330485maximath_1커다란 상품 (IOI17_prize)C++11
90 / 100
125 ms512 KiB
#include "prize.h" #include <vector> using namespace std; int find_best(int n) { int loli = -1, mx = 0, pre = 0; for(int i = 0; i < 474; i ++){ vector<int> v = ask(i); if(v[0] + v[1] == 0) return i; if(v[0] + v[1] > mx){ mx = v[0] + v[1]; loli = i; pre = v[0]; } } for(;;){ int lf = loli + 1, rg = n - 1; int ans; for(int md; lf <= rg;){ md = (lf + rg) / 2; vector<int> v = ask(md); if(v[0] + v[1] == 0) return md; if(v[0] + v[1] == mx && v[0] == pre) lf = md + 1; else rg = md - 1; if(v[0] + v[1] != mx) ans = md; } for(int i = ans; i < n; i ++){ vector<int> v = ask(i); if(v[0] + v[1] == 0) return i; if(v[0] + v[1] == mx){ loli = i; pre = v[0]; break; } } } return 0; }

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

prize.cpp: In function 'int find_best(int)':
prize.cpp:19:7: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   19 |   int ans;
      |       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...