제출 #702811

#제출 시각아이디문제언어결과실행 시간메모리
702811yhkhooXylophone (JOI18_xylophone)C++17
0 / 100
97 ms208 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...