이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
int A[200009], QQ; map<int, vector<int> >Map;
vector<int> asks(int pos) {
if (Map[pos].size() >= 1) return Map[pos];
Map[pos] = ask(pos); QQ++;
return Map[pos];
}
vector<int> find_next(vector<int> R) {
int S = sqrt(R.size()) + 1;
int TT = 0, U = 1; while (U <= 1000) { U *= S; TT++; }
int maxp = 0;
for (int i = 0; i < TT; i++) {
vector<int> P = asks(R[rand() % R.size()]);
maxp = max(maxp, P[0] + P[1]);
}
int cx = 0; vector<int> T;
while (cx < (int)R.size()) {
vector<int> P = asks(R[cx]);
if (P[0] + P[1] != maxp) { T.push_back(R[cx]); cx++; continue; }
if (cx + 1 == (int)R.size()) break;
int B = 512;
if (R.size() <= 500) B = 32;
if (R.size() <= 30) B = 8;
int cl = 0, cr = min((int)R.size() - cx, B), cm, maxn = cx; bool flag = false;
while (cr - cl >= 2) {
cm = (cl + cr) / 2;
//cout << "cx = " << cx << ", cl = " << cl << ", cr = " << cr << ", cm = " << cm << ", maxn = " << maxn << endl;
vector<int> Q = asks(R[cx + cm]);
if (P == Q) {
if (flag == true) cl = cm;
else cr *= 2;
if (flag == false && cr >= (int)R.size() - cx) { flag = true; cr = R.size() - cx; }
maxn = max(maxn, cx + cm);
}
else { cr = cm; flag = true; }
}
if (maxn == (int)R.size() - 1) break;
T.push_back(R[maxn + 1]);
cx = maxn + 2;
if (T.size() == maxp) break;
}
//for (int i = 0; i < T.size(); i++) cout << T[i] << ", "; cout << endl;
return T;
}
int find_best(int n) {
vector<int> E; for (int i = 0; i < n; i++) E.push_back(i);
while (E.size() >= 2) { E = find_next(E); }
return E[0];
}
컴파일 시 표준 에러 (stderr) 메시지
prize.cpp: In function 'std::vector<int> find_next(std::vector<int>)':
prize.cpp:48:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (T.size() == maxp) break;
~~~~~~~~~^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |