#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
void solve(int n){
int diff[n + 1] = {0};
for(int i = 2; i <= n; i++){
diff[i] = query(i - 1, i);
}
int mult[n + 1] = {0}; mult[1] = 1, mult[2] = 1;
for(int i = 3, add; i <= n; i++){
add = query(i - 2, i);
if(add < diff[i - 1] + diff[i]) mult[i] = -1;
else mult[i] = 1;
}
int arr[n + 1] = {0}, curm = mult[1], add = n;
for(int i = 2; i <= n; i++){
curm *= mult[i];
arr[i] = arr[i - 1] + curm * diff[i];
add = min(add, n - arr[i]);
}
// for(int i = 1; i <= n; i++) cout << arr[i] << ' '; cout << endl;
bool mun = 0; int madd = 0;
for(int i = 1; i <= n; i++){
arr[i] += add;
if(arr[i] == n && !mun){
// cout << madd << endl;
madd = n + 1;
}else if(arr[i] == 1) mun = 1;
// cout << madd << endl;
}
// for(int i = 1; i <= n; i++) cout << diff[i] << ' '; cout << endl;
// for(int i = 1; i <= n; i++) cout << mult[i] << ' '; cout << endl;
// cout << add << ' ' << madd << endl;
for(int i = 1; i <= n; i++){
// cout << "answer(" << i << ", " << abs(madd - arr[i]) << ')' << endl;
answer(i, abs(madd - arr[i]));
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |