이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
static int A[5001];
void solve(int N) {
//bs for 1
int s=1, e=N-1;
while(s!=e){
int mid = (s+e)/2;
if(query(mid, N) != N-1){
e = mid-1;
}
else{
s = mid;
}
}
A[s] = 1;
unordered_set<int> aset;
aset.insert(1);
if(s-1 != 0){
A[s-1] = query(s-1, s)+1;
aset.insert(A[s-1]);
}
for(int i=s-2; i>0; i--){ // go to the left
int temp1 = query(i, i+1);
if(A[i+1] - temp1 < 2 || aset.count(A[i+1] - temp1)){ // not possible to be less
A[i] = A[i+1] + temp1;
}
else if(A[i+1] + temp1 > N || aset.count(A[i+1] + temp1)){ // not possible to be more
A[i] = A[i+1] - temp1;
}
else{ // can be both
int temp2 = query(i, i+2);
if(temp1 == temp2){ // A[i+2] is inbetween A[i+1] and A[i]
if(A[i+2] > A[i+1]){
A[i] = A[i+1] + temp1;
}
else{
A[i] = A[i+1] - temp1;
}
}
else{ // A[i+2] is outside of the range of A[i+1] and A[i]
if(A[i+2] > A[i+1]){
if(temp2 == A[i+2] - A[i+1]){ // A[i] is inbetween A[i+2] and A[i+1]
A[i] = A[i+1] + temp1;
}
else{
A[i] = A[i+1] - temp1;
}
}
else{
if(temp2 == A[i+1] - A[i+2]){ // A[i] is inbetween A[i+2] and A[i+1]
A[i] = A[i+1] - temp1;
}
else{
A[i] = A[i+1] + temp1;
}
}
}
}
aset.insert(A[i]);
}
A[s+1] = query(s, s+1)+1;
aset.insert(A[s+1]);
for(int i=s+2; i<=N; i++){ // go to the right
int temp1 = query(i-1, i);
if(A[i-1] - temp1 < 2 || aset.count(A[i-1] - temp1)){ // not possible to be less
A[i] = A[i-1] + temp1;
}
else if(A[i-1] + temp1 > N || aset.count(A[i-1] + temp1)){ // not possible to be more
A[i] = A[i-1] - temp1;
}
else{ // can be both
int temp2 = query(i-2, i);
if(temp1 == temp2){ // A[i-2] is inbetween A[i-1] and A[i]
if(A[i-2] > A[i-1]){
A[i] = A[i-1] + temp1;
}
else{
A[i] = A[i-1] - temp1;
}
}
else{ // A[i-2] is outside of the range of A[i-1] and A[i]
if(A[i-2] > A[i-1]){
if(temp2 == A[i-2] - A[i-1]){ // A[i] is inbetween A[i-2] and A[i-1]
A[i] = A[i-1] + temp1;
}
else{
A[i] = A[i-1] - temp1;
}
}
else{
if(temp2 == A[i-1] - A[i-2]){ // A[i] is inbetween A[i-2] and A[i-1]
A[i] = A[i-1] - temp1;
}
else{
A[i] = A[i-1] + temp1;
}
}
}
}
aset.insert(A[i]);
}
for(int i = 1; i <= N; i++) {
answer(i, A[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... |