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;
#define sz(x) (int)x.size()
#define fi first
#define se second
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 5005;
int n;
int a[maxn];
int f[maxn], g[maxn];
int b[maxn];
void build_b(int sign)
{
b[2] = (sign ? 1 : -1) * f[1];
for(int i = 3; i <= n; ++i)
{
if(g[i - 2] != f[i - 2] + f[i - 1])
sign ^= 1;
b[i] = b[i - 1] + (sign ? 1 : -1) * f[i - 1];
}
}
void solve(int N)
{
n = N;
if(N == 2)
{
answer(1, 1);
answer(1, 2);
return;
}
for(int i = 1; i < n; ++i)
f[i] = query(i, i + 1);
for(int i = 1; i < n - 1; ++i)
g[i] = query(i, i + 2);
build_b(1);
pii mn = pii(0, 1), mx = pii(0, 1);
for(int i = 2; i <= n; ++i)
{
mn = min(mn, pii(b[i], i));
mx = max(mx, pii(b[i], i));
}
if(mn.se > mx.se)
build_b(0);
mn = mx = pii(0, 1);
for(int i = 2; i <= n; ++i)
{
mn = min(mn, pii(b[i], i));
mx = max(mx, pii(b[i], i));
}
for(int i = 1; i <= n; ++i)
answer(i, b[i] - mn.fi + 1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |