#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
static int A[5000];
int a[5005];
void solve(int N) {
int n=N;
int value = query(1, N);
map<pair<int,int>,int> mp;
for(int i=1;i<n-1;i++){
int t=query(i,i+1);
mp[{i,i+1}]=t;
}
for(int i=1;i<n-2;i++){
int t=query(i,i+2);
if(mp[{i,i+1}]+mp[{i+1,i+2}]==t){
mp[{i,i+2}]=1;
}
}
int p1=1,p2=N;
while(p2>p1){
int v=query(p1,p2);
if(v!=value){
p2++;
break;
}
p2--;
}
while(p1<p2){
int v=query(p1,p2);
if(v!=value){
p1--;
break;
}
p1++;
}
a[p1]=1;
a[p2]=n;
for(int i=p1-1;i>=0;i--){
int t=mp[{i,i+1}];
if(i==p1-1){
a[i]=1+t;
}
else{
if(mp[{i,i+2}]){
if(a[i+1]>a[i+2]){
a[i]=a[i+1]+t;
}
else{
a[i]=a[i+1]-t;
}
}
else{
if(a[i+1]>a[i+2]){
a[i]=a[i+1]-t;
}
else{
a[i]=a[i+1]+t;
}
}
}
}
if(p1!=p2-1){
for(int i=p1+1;i<p2;i++){
int t=mp[{i-1,i}];
if(i==p1+1){
a[i]=1+t;
}
else{
if(mp[{i-2,i}]){
if(a[i-2]>a[i-1]){
a[i]=a[i-1]-t;
}
else{
a[i]=a[i-1]+t;
}
}
else{
if(a[i-2]>a[i-1]){
a[i]=a[i-1]+t;
}
else{
a[i]=a[i-1]-t;
}
}
}
}
}
for(int i=p2+1;i<=n;i++){
int t=mp[{i-1,i}];
if(i==p2+1){
a[i]=n-t;
}
else{
if(mp[{i-2,i}]){
if(a[i-2]>a[i-1]){
a[i]=a[i-1]-t;
}
else{
a[i]=a[i-1]+t;
}
}
else{
if(a[i-2]>a[i-1]){
a[i]=a[i-1]+t;
}
else{
a[i]=a[i-1]-t;
}
}
}
}
for(int i=1;i<=n;i++){
answer(i,a[i]);
}
}
Compilation message
xylophone.cpp:5:12: warning: 'A' defined but not used [-Wunused-variable]
static int A[5000];
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |