제출 #497857

#제출 시각아이디문제언어결과실행 시간메모리
497857penguin133Xylophone (JOI18_xylophone)C++14
47 / 100
100 ms432 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; int ans[5005], taken[5005]; void solve(int N) { int x = 2,prev= 0 ; while(query(x, N) == N - 1)x++; ans[x-1] = 1; taken[1] = true; for(int i=x-2;i>=1;i--){ int y = query(i, i+1); if(i == x-2)ans[i] = y + 1; else{ if(ans[i+1] -y <= 1 || taken[ans[i+1] - y])ans[i] = ans[i+1] + y; else if(ans[i+1] + y >= N || taken[ans[i+1] + y])ans[i] = ans[i+1] - y; else{ int y2 = query(i, i+2); if(y2 != prev){ if(ans[i+1] + y == min(ans[i+1] ,ans[i+2]) + y2)ans[i] = ans[i+1] + y; else ans[i] = ans[i+1] - y; } else{ if(ans[i+1] > ans[i+2])ans[i]=ans[i+1] -y; else ans[i] = ans[i+1] + y; } } } taken[ans[i]] = true; prev = y; } prev = 0; for(int i=x;i<=N;i++){ int y = query(i-1, i); if(i == x)ans[i] = y + 1; else{ if(ans[i-1] -y <= 1 || taken[ans[i-1] - y])ans[i] = ans[i-1] + y; else if(ans[i-1] + y > N || taken[ans[i-1] + y])ans[i] = ans[i-1] - y; else{ int y2 = query(i-2, i); if(y2 != prev){ if(ans[i-1] + y == min(ans[i-1], ans[i-2]) + y2)ans[i] = ans[i-1] + y; else ans[i] = ans[i-1] - y; } else{ if(ans[i-1] > ans[i-2])ans[i]=ans[i-1] -y; else ans[i] = ans[i-1] + y; } } } prev = y; taken[ans[i]] = true; } for(int i=1;i<=N;i++)answer(i, ans[i]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...