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 n, p1[5005], p2[5005], a[5005];
bool mark[50005];
void ANSWER(vector<int> &v) {
for (int i = 0; i < v.size(); i++) answer(i+1,v[i]);
}
void solve(int n) {
vector<int> ANS;
int x = query(1, 2);
for (int i = 3; i <= n; i++) {
p1[i] = query(i-1, i);
p2[i] = query(i-2, i);
}
a[1] = x;
a[2] = 0;
for (int i = 3; i <= n; i++) {
int val =a[i-1] + p1[i];
a[i] = val;
if(max({a[i], a[i-1],a[i-2]}) - min({a[i], a[i-1], a[i-2]}) == p2[i]) a[i] = val;
else a[i] = a[i-1] - p1[i];
}
int mn = n;
for (int i = 1; i <= n; i++) {
mn = min(mn, a[i]);
}
if(mn > 0) mn = -(mn-1);
else mn = abs(mn-1);
bool ac = true;
int pos1, posn;
for (int i = 1; i <= n; i++) {
a[i]+=mn;
mark[a[i]] = true;
if(a[i] > n) ac = false;
if(a[i] == 1) pos1 = i;
if(a[i] == n) posn = i;
}
for (int i = 1; i <= n; i++) if(!mark[i]) ac = false;
if(pos1 > posn) ac = false;
if(ac) {
//ANSWER
for (int i = 1; i <= n; i++) ANS.push_back(a[i]);
ANSWER(ANS);
}
else {
a[1] = 0, a[2] = x;
for (int i = 3; i <= n; i++) {
int val = a[i-1] + p1[i];
a[i] = val;
if(max({a[i], a[i-1],a[i-2]}) - min({a[i], a[i-1], a[i-2]}) == p2[i]) a[i] = val;
else a[i] = a[i-1] - p1[i];
}
int mn = n;
for (int i = 1; i <= n; i++) {
mn = min(mn, a[i]);
}
if(mn > 0) mn = -(mn-1);
else mn = abs(mn-1);
for (int i = 1; i <= n; i++) a[i] += mn;
for (int i = 1; i <= n; i++) ANS.push_back(a[i]);
ANSWER(ANS);
}
}
Compilation message (stderr)
xylophone.cpp: In function 'void ANSWER(std::vector<int>&)':
xylophone.cpp:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for (int i = 0; i < v.size(); i++) answer(i+1,v[i]);
| ~~^~~~~~~~~~
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:46:5: warning: 'pos1' may be used uninitialized in this function [-Wmaybe-uninitialized]
46 | if(ac) {
| ^~
xylophone.cpp:46:5: warning: 'posn' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |