이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "prize.h"
#ifdef ONPC
#include "t_debug.cpp"
#else
#define debug(...) 42
#endif
#define sz(a) ((int)(a).size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll INFL = 1e18;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; }
const int N = 2e5, LOGN = 17, MOD = 1e9+7;
int find_best(int n) {
vector<int> res;
int mx = 0, L = 0, R = n-1;
for (int i = 0; i < min(n, 500); i++) {
res = ask(i);
if (res[0] + res[1] > mx) {
mx = res[0] + res[1];
L = i;
} else if (res[0] + res[1] == 0) {
return i;
}
}
for (; R >= L; R--) {
res = ask(R);
if (res[0] + res[1] == mx) break;
else if (res[0] + res[1] == 0) return R;
}
int ans = -1;
function<void(int,int,int)> solve = [&](int L, int R, int count)->void {
if (count <= 0) return;
if (L > R) return;
if (~ans) return;
if (R - L + 1 == count) {
for (int i = L; i <= R; i++) {
auto res = ask(i);
if (res[0] + res[1] == 0) ans = i;
break;
}
return;
}
vector<int> res;
while (true) {
res = ask(L);
if (res[0] + res[1] == 0) {
ans = L;
return;
}else if (res[0] + res[1] == mx) break;
else {L++; count--;}
}
int mid1 = (L + R) / 2;
int mid2 = mid1;
while (true) {
auto res2 = ask(mid2);
if (res2[0] + res2[1] < mx) {
if (res2[0] + res2[1] == 0) {
ans = mid2;
return;
}
mid2++;
} else {
int rem = mid2 - mid1;
int count1 = res2[0] - res[0] - rem;
int count2 = count - count1 - rem;
solve(L+1, mid1-1, count1);
solve(mid2+1, R, count2);
return;
}
}
};
debug(mx, L, R, res);
solve(L, R, res[0]);
return ans;
}
/*
█████ █████ ███ ████
▒▒███ ▒▒███ ▒▒▒ ▒▒███
███████ ████████ ███████ ████ ▒███ █████ ████ ██████ ████████
███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███ ▒███ ▒▒███ ▒███ ███▒▒███▒▒███▒▒███
▒███ ▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒
▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███
▒▒████████ █████ ▒▒████████ █████ █████ ▒▒███████ ▒▒██████ █████
▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒███ ▒▒▒▒▒▒ ▒▒▒▒▒
███ ▒███
▒▒██████
▒▒▒▒▒▒
*/
컴파일 시 표준 에러 (stderr) 메시지
prize.cpp: In function 'int find_best(int)':
prize.cpp:6:24: warning: statement has no effect [-Wunused-value]
6 | #define debug(...) 42
| ^~
prize.cpp:78:5: note: in expansion of macro 'debug'
78 | debug(mx, L, R, res);
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |