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"
//#include "Lgrader.cpp"
using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (5042);
int n;
bool check(vector<int> p)
{
vector<bool> used(p.size(), 0);
int pmax, pmin, mx = -1, mn = (int)1e9;
for(int i = 0; i < n; i++)
{
if(chkmax(mx, p[i])) pmax = i;
if(chkmin(mn, p[i])) pmin = i;
if(p[i] >= n) return false;
if(used[p[i]]) return false;
used[p[i]] = true;
}
if((mx != (int)p.size() - 1) || mn != 0 || pmax < pmin)
return false;
return true;
}
int ask(int l, int r) { return query(l + 1, r + 1); }
void fix(vector<int> &p)
{
int mn = 1e9;
for(int &x: p)
chkmin(mn, x);
for(int &x: p)
x += -mn;
//for(int x: p)
// cerr << x << " ";
//cerr << endl << flush;
}
int ask2[MAXN], ask3[MAXN];
int my_ask(int a, int b, int c)
{
int ret = 0;
chkmax(ret, a - b);
chkmax(ret, b - a);
chkmax(ret, a - c);
chkmax(ret, c - a);
chkmax(ret, c - b);
chkmax(ret, b - c);
return ret;
}
void solve(int N)
{
n = N;
for(int i = 0; i + 1 < n; i++) ask2[i] = ask(i, i + 1);
for(int i = 0; i + 2 < n; i++) ask3[i] = ask(i, i + 2);
vector<int> A(n, 0);
A[0] = 0;
A[1] = ask2[0];
for(int i = 2; i < n; i++)
{
if(my_ask(A[i - 2], A[i - 1], A[i - 1] + ask2[i - 1]) == ask3[i - 2]) A[i] = A[i - 1] + ask2[i - 1];
else A[i] = A[i - 1] - ask2[i - 1];
}
fix(A);
if(check(A))
{
for(int i = 0; i < n; i++)
answer(i + 1, A[i] + 1);
return;
}
A.assign(n, 0);
A[0] = 0;
A[1] = -ask2[0];
for(int i = 2; i < n; i++)
{
if(my_ask(A[i - 2], A[i - 1], A[i - 1] + ask2[i - 1]) == ask3[i - 2]) A[i] = A[i - 1] + ask2[i - 1];
else A[i] = A[i - 1] - ask2[i - 1];
}
fix(A);
if(check(A))
{
for(int i = 0; i < n; i++)
answer(i + 1, A[i] + 1);
return;
}
}
Compilation message (stderr)
xylophone.cpp: In function 'bool check(std::vector<int>)':
xylophone.cpp:27:42: warning: 'pmin' may be used uninitialized in this function [-Wmaybe-uninitialized]
if((mx != (int)p.size() - 1) || mn != 0 || pmax < pmin)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
xylophone.cpp:27:42: warning: 'pmax' 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... |