이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prize.h"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
#define pb push_back
const int B = 472;
int val;
vector<vector<int>> memo;
vector<int> K(int i) {
if(memo[i][0] != -1) return memo[i];
return memo[i] = ask(i);
}
vector<int> find(int l, int r){
vector<int> ans;
if (l > r)return ans;
vector<int> x = K(r);
if (x[0] + x[1] != val){
ans = find(l, r - 1);
ans.pb(r);
return ans;
}
int tl = l, tr = r;
while (tl != tr){
int mid = (tl + tr) / 2;
vector<int> y = K(mid);
if (y[0] + y[1] != val){
tl = mid + 1;
continue;
}
if (y[1] != x[1])tl = mid + 1;
else tr = mid;
}
if (l == tr)return ans;
else{
ans = find(l, tr - 2);
ans.pb(tr - 1);
return ans;
}
}
int find_best(int n){
memo.resize(n, {-1, -1});
vector<int> non_lolipop, x;
for (int i = 0; i < B && i < n; i++){
x = K(i);
val = max(val, x[0] + x[1]);
}
for (int i = 0; i < n; i += B){
x = find(i, min(n - 1, i + B - 1));
for (int i = 0; i < x.size(); i++)non_lolipop.pb(x[i]);
}
for (int i = 0; i < non_lolipop.size(); i++){
x = K(non_lolipop[i]);
if (x[0] + x[1] == 0)return non_lolipop[i];
}
}
컴파일 시 표준 에러 (stderr) 메시지
prize.cpp: In function 'int find_best(int)':
prize.cpp:69:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for (int i = 0; i < x.size(); i++)non_lolipop.pb(x[i]);
| ~~^~~~~~~~~~
prize.cpp:71:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int i = 0; i < non_lolipop.size(); i++){
| ~~^~~~~~~~~~~~~~~~~~~~
prize.cpp:62:14: warning: control reaches end of non-void function [-Wreturn-type]
62 | vector<int> non_lolipop, x;
| ^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |