This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <xylophone.h>
using namespace std;
void solve(int n){
vector<int> v(n+1),th(n+1),se(n+1);
for(int i=1;i<=n;i++){
se[i] = query(i-1,i);
if(i != 1) th[i] = query(i-2,i);
}
for(int i=1;i<=n;i++){
int ok = 1; v[1] = i;
vector<int> vis(n+1,0); vis[i] = 1;
for(int j=2;j<=n;j++){
if(th[j] == se[j-1]){
v[j] = v[j-1] + (v[j-2] > v[j-1] ? se[j] : -se[j]);
}
else{
if(v[j-2] > v[j-1]){
if(se[j] == th[j]) v[i] = v[j-1] + se[j];
else v[j] = v[j-1] - se[j];
}
else{
if(th[j] == se[j]) v[j] = v[j-1] - se[j];
else v[j] = v[j-1] + se[j];
}
}
if(v[j] > n || v[j] <= 0 || vis[v[j]]){
ok = 0;
break;
}
vis[v[j]] = 1;
}
if(!ok) continue;
for(int j=1;j<=n;j++){
answer(j,v[j]);
}
return;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |