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;
int ans1[5005], ans2[5005];
void solve(int n){
// query(l, r); -> hit block l to r and determine the difference between maximum and minimum value within those range
// answer(i, x); -> the value of Ai is x
int b1 = 1, b2 = -1;
ans1[1] = ans2[1] = 1;
int prevDiff, diff, diff2;
diff = query(1, 2);
ans1[2] = ans1[1]+diff*b1;
ans2[2] = ans2[1]+diff*b2;
prevDiff = diff;
int lowest1 = min(ans1[1], ans1[2]), lowest2 = min(ans2[1], ans2[2]);
for(int i = 3; i <= n; i++){
diff = query(i-1, i);
diff2 = query(i-2, i);
if(diff2 != diff+prevDiff){
b1 *= -1;
b2 *= -1;
}
ans1[i] = ans1[i-1]+diff*b1;
ans2[i] = ans2[i-1]+diff*b2;
lowest1 = min(lowest1, ans1[i]);
lowest2 = min(lowest2, ans2[i]);
prevDiff = diff;
}
bool pass1 = false, pass2 = false, flag1 = true, flag2 = true;
for(int i = 1; i <= n; i++){
ans1[i] += lowest1*-1+1;
ans2[i] += lowest2*-1+1;
if(ans1[i] == 1){
pass1 = true;
}
if(ans2[i] == 1){
pass2 = true;
}
if((ans1[i] == n && !pass1) || ans1[i] > n){
flag1 = false;
}
if((ans2[i] == n && !pass2) || ans2[i] > n){
flag2 = false;
}
}
if(flag1){
for(int i = 1; i <= n; i++){
printf("%d ", ans1[i]);
}
printf("\n");
for(int i = 1; i <= n; i++){
answer(i, ans1[i]);
}
} else {
for(int i = 1; i <= n; i++){
printf("%d ", ans2[i]);
}
printf("\n");
for(int i = 1; i <= n; i++){
answer(i, ans2[i]);
}
}
}
Compilation message (stderr)
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:34:51: warning: variable 'flag2' set but not used [-Wunused-but-set-variable]
34 | bool pass1 = false, pass2 = false, flag1 = true, flag2 = true;
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |