이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
#define oo 2000000000
bool asked[N];
vector<int> answer[N] , v;
vector< pair<int,int> > v2;
int mx = 0 ;
vector<int> get(int i){
if(asked[i])
return answer[i];
asked[i] = true;
answer[i] = ask(i);
if(answer[i][0] + answer[i][1] == mx) v2.push_back(make_pair(answer[i][0],i)); else v.push_back(i);
return answer[i];
}
int solve(int s,int e){
int res = e;
vector<int> v1 = get(s);
while(e >= s){
int mid = (s + e) / 2;
vector<int> cur = get(mid);
if(cur[0] + cur[1] == mx && cur[0] == v1[0])
s = mid + 1;
else {
res = mid;
e = mid - 1;
}
}
return res;
}
int find_best(int n) {
srand(time(0));
int num = min(n,480);
set < int > st;
for(int i=0;i<n;i++) st.insert(i);
for(int i=0;i<num;i++){
int num = rand() % n;
while(true){
set < int > :: iterator it =st.lower_bound(num);
if(it != st.end()){
vector<int> res = get(*it);
int cur = res[0] + res[1];
mx = max(mx,cur);
st.erase(it);
break;
}
num = rand() % n;
}
}
int low = 0;
while(true){
int high = n - 1;
vector<int> cur = get(low);
if(cur[0] + cur[1] == 0) return low;
if(cur[0] + cur[1] != mx){
low++;
continue;
}
for(int i=0;i<v2.size();i++){
if(v2[i].second >= low && v2[i].first != cur[0]){
high = min(high,v2[i].second);
}
else if(v2[i].second >= low){
low = max(low,v2[i].second);
}
}
bool flag = false;
for(int i=0;i<v.size();i++){
vector<int> tmp = get(v[i]);
if(tmp[0] + tmp[1] == 0) return v[i];
if(v[i] > low){
high = min(high,v[i]);
}
}
if(flag) continue;
low = solve(low,high);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
prize.cpp: In function 'int find_best(int)':
prize.cpp:64:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v2.size();i++){
^
prize.cpp:73:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size();i++){
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |