제출 #542494

#제출 시각아이디문제언어결과실행 시간메모리
542494status_codingXylophone (JOI18_xylophone)C++14
100 / 100
81 ms560 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; int n; int a[5005]; map<int, int> fr; int findN() { int st=2, dr=n, mij, last=-1; while(st <= dr) { mij = (st+dr)/2; //cout<<1<<' '<<mij<<'\n'; if(query(1, mij) == n-1) { last=mij; dr=mij-1; } else st=mij+1; } return last; } bool bad(int x) { if(x > n) return true; if(x <= 0) return true; if(fr[x]) return true; return false; } int check(int a, int b, int c) { return max({a, b, c}) - min({a, b, c}); } void solve(int N) { n=N; int p = findN(); if(p == -1) exit(1); a[p] = n; fr[n] = 1; int mini=n; for(int i=p-1;i>=1;i--) { int dif = query(i, i+1); int x1 = a[i+1] - dif; int x2 = a[i+1] + dif; if(bad(x1)) a[i]=x2; else if(bad(x2)) a[i]=x1; else { int nQ = query(i, i+2); if(check(x2, a[i+1], a[i+2]) == nQ) a[i]=x2; else a[i]=x1; } mini=min(mini, a[i]); fr[ a[i] ] =1; } mini=n; for(int i=p+1;i<=n;i++) { int dif = query(i-1, i); int x1 = a[i-1] - dif; int x2 = a[i-1] + dif; if(bad(x1)) a[i]=x2; else if(bad(x2)) a[i]=x1; else { int nQ = query(i-2, i); if(check(a[i-2], a[i-1], x2) == nQ) a[i]=x2; else a[i]=x1; } mini=min(mini, a[i]); fr[ a[i] ] =1; } /* for(int i=1;i<=n;i++) cout<<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...