이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <set>
#include <cmath>
#include <cstring>
#include "prize.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll, ll> ii;
vi mem[(int)2e5 + 1];
bool done[(int)2e5 + 1];
vi pitaj(int idx){
if (done[idx])
return mem[idx];
done[idx] = true;
return mem[idx] = ask(idx);
}
int bin_search(int lijevo, int beg, int end, int maxi){
if (beg > end)
return -1;
return -1;
int l = beg, r = end;
vi t;
while(l < r){
int mid = (l + r)/2;
t = pitaj(mid);
if (t[0] + t[1] == 0)
return mid;
if (t[0] + t[1] == maxi){
if (lijevo - t[1])
r = mid - 1;
else
l = mid + 1;
}
else
r = mid;
}
while(end >= l){
vi r = pitaj(l);
if (r[0] + r[1] == 0)
return l;
if (r[0] + r[1] == maxi)
break;
l++;
}
if (mem[l][1] - mem[end + 1][1])
return bin_search(mem[l][1], l + 1, end, maxi);
return -1;
}
int find_best(int n){
memset(done, false, sizeof done);
int maxi = 0;
int grupa = 460, br = n/460;
int curr = 0;
vi idx;
for (int i = 0; i < grupa; i++){
if (curr >= n)
break;
vi res = pitaj(curr);
maxi = max(maxi, res[0] + res[1]);
if (res[0] + res[1] == 0)
return curr;
idx.push_back(curr);
curr += br;
if (i < (n%460))
curr++;
}
done[n] = true; mem[n] = {maxi, 0}; idx.push_back(n);
for (int i = 0; i < idx.size() - 1; i++){
int x = idx[i], y = idx[i + 1];
int res = -1;
while(y >= x){
vi r = pitaj(y);
if (r[0] + r[1] == 0)
return y;
if (r[0] + r[1] == maxi)
break;
y--;
}
while(y >= x){
vi r = pitaj(x);
if (r[0] + r[1] == 0)
return x;
if (r[0] + r[1] == maxi)
break;
x++;
}
if (mem[x][1] - mem[y][1] && x != y + 1)
res = bin_search(mem[x][1], x + 1, y - 1, maxi);
if (res != -1)
return res;
}
}
컴파일 시 표준 에러 (stderr) 메시지
prize.cpp: In function 'int find_best(int)':
prize.cpp:82:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < idx.size() - 1; i++){
~~^~~~~~~~~~~~~~~~
prize.cpp:107:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |