#include<bits/stdc++.h>
#include "xylophone.h"
using namespace std;
void solve(int n) {
vector<int> a(n+2);
vector<int> b(n+1) , c(n+1);
for(int i = 1 ; i < n ; i++){
b[i] = query(i , i+1);
}
for(int i = 2 ; i < n ; i++){
c[i] = query(i-1 , i+1);
}
for(int i = 1 ; i <= n ; i++){
a[i] = 1;
a[i+1] = 1 + b[i];
a[i-1] = b[i-1] + 1;
for(int j = i + 2 ; j <= n ; j++){
if(a[j-1] > a[j-2]){
if(b[j-2] < c[j-1]) a[j] = a[j-1] + b[j-1];
else a[j] = a[j-1] - b[j-1];
}else{
if(b[j-2] < c[j-1]) a[j] = a[j-1] - b[j-1];
else a[j] = a[j-1] + b[j-1];
}
}
for(int j = i - 2 ; j >= 1 ; j--){
if(a[j+1] > a[j+2]){
if(b[j+1] < c[j+1]) a[j] = a[j+1] + b[j];
else a[j] = a[j+1] - b[j];
}else{
if(b[j+1] < c[j+1]) a[j] = a[j+1] - b[j];
else a[j] = a[j+1] + b[j];
}
}
vector<int> cnt(n+1);
int C = 0;
for(int i = 1 ; i <= n ; i ++){
if(a[i] < 1 or a[i] > n){
C=1; break;
}
if(cnt[a[i]] == 1){
C=1; break;
}
cnt[a[i]]=1;
}
if(C==0){
for(int i = 1 ; i <= n ; i++) answer(i , a[i]);
break;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
1 ms |
344 KB |
Wrong Answer [6] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
1 ms |
344 KB |
Wrong Answer [6] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
1 ms |
344 KB |
Wrong Answer [6] |
4 |
Halted |
0 ms |
0 KB |
- |