이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
//static int A[5000];
int cnt = 0;
inline int get(int a, int b, int pa, int pb, int pc) {
cnt += 2;
if(cnt > 10000) {
while(1) {
}
}
int bc = query(min(pb, pc), max(pb, pc)), ac = query(min(pa, pc), max(pa, pc));
if(a < b) {
if(bc == ac) {
return b - bc;
}
if(ac == abs(a - b)) {
return b - bc;
}
return b + bc;
}
else {
if(bc == ac) {
return b + bc;
}
if(ac == abs(a - b)) {
return b + bc;
}
return b - bc;
}
}
void solve(int n) {
int pos = n + 1, i;
for(int step = 1 << 15; step; step >>= 1) {
if(pos - step >= 1 && query(pos - step, n) < n - 1) {
pos -= step;
}
}
pos--; // 1
vector <int> sol(n + 2);
sol[pos] = 1;
if(pos > 1) {
sol[pos - 1] = 1 + query(pos - 1, pos);
}
int a = sol[pos], b = sol[pos - 1];
for(i = pos - 2; i >= 1; i--) {
int c = get(a, b, i + 2, i + 1, i);
sol[i] = c;
a = b;
b = c;
}
if(pos < n) {
sol[pos + 1] = 1 + query(pos, pos + 1);
}
a = sol[pos], b = sol[pos + 1];
for(i = pos + 2; i <= n; i++) {
int c = get(a, b, i - 2, i - 1, i);
sol[i] = c;
a = b;
b = c;
}
for(i = 1; i <= n; i++) {
answer(i, sol[i]);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |