#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
#define ll long long
ll d2[(ll)1e5 + 100], d3[(ll)1e5 + 100], a[(ll)1e5 + 100], pos[(ll)1e5 + 100];
bool check(ll x, ll n){
a[2] = x;
for(int i = 3; i <= n;i++){
if(d3[i] == d2[i-1]){
if(a[i-1] < a[i-2]){
a[i] = a[i-1] + d2[i];
}
else a[i] = a[i-1] - d2[i];
}
else{
if(a[i-2] < a[i-1]){
if(d2[i-1] + d2[i] == d3[i]){
a[i] = a[i-1] + d2[i];
}
else{
a[i] = a[i-1] - d2[i];
}
}
else{
if(d2[i] == d3[i]){
a[i] = a[i-1] + d2[i];
}
else a[i] = a[i-2] - d3[i];
}
}
}
for(int i = 1; i <= n;i++) {
if(a[i] < 0) return 0;
pos[a[i]] = i;
}
ll ok = (pos[1] < pos[n]);
for(int i = 1; i <= n;i++) ok &= (pos[i] > 0);
if(ok){
for(int i = 1; i <= n;i++) answer(i, a[i]);
return 1;
}
else return 0;
}
void solve(int n){
for(int i = 2; i <= n;i++) d2[i] = query(i - 1, i);
for(int i = 3; i <= n;i++) d3[i] = query(i - 2, i);
for(int val = 1; val <= n;val++){
for(int i = 1; i <= n;i++) pos[i] = 0;
a[1] = val;
if(check(a[1] + d2[2], n)) return;
if(check(a[1] - d2[2], n)) return;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Incorrect |
1 ms |
2392 KB |
Wrong Answer [7] |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Incorrect |
1 ms |
2392 KB |
Wrong Answer [7] |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Incorrect |
1 ms |
2392 KB |
Wrong Answer [7] |
8 |
Halted |
0 ms |
0 KB |
- |