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 ll long long
#define pb push_back
void solve(int n)
{
/*o.resize(n+1);
for(int i = 1; i<=n; i++)
cin >> o[i];*/
vector<vector<ll>> q(n+1, vector<ll>(n+1));
for(int i = 1; i<n; i++)
q[i][i+1] = query(i, i+1);
for(int i = 1; i<n-1; i++)
q[i][i+2] =query(i, i+2);
bool flag = true;
vector<ll> arr(n+1);
arr[1] = 0;
for(int i = 1; i<n; i++)
{
if(q[i][i+2]==q[i][i+1] + q[i+1][i+2])
{
if(flag)
arr[i+1] = arr[i] + q[i][i+1];
else
arr[i+1] = arr[i] - q[i][i+1];
}
else
{
if(flag)
arr[i+1] = arr[i] + q[i][i+1];
else
arr[i+1] = arr[i] - q[i][i+1];
flag = !flag;
}
}
ll mini = 1e9;
for(int i = 1; i<=n; i++)
mini = min(mini, arr[i]);
ll dif = 1-mini;
for(int i = 1; i<=n; i++)
arr[i]+=dif;
int l = 1, r = n;
for(int i = 1; i<=n; i++)
{
if(arr[i]==1)
l = i;
if(arr[i]==n)
r = i;
}
if(l>=r)
{
flag = false;
arr.assign(n+1, 0);
arr[1] = 0;
for(int i = 1; i<n; i++)
{
if(q[i][i+2]==q[i][i+1] + q[i+1][i+2])
{
if(flag)
arr[i+1] = arr[i] + q[i][i+1];
else
arr[i+1] = arr[i] - q[i][i+1];
}
else
{
if(flag)
arr[i+1] = arr[i] + q[i][i+1];
else
arr[i+1] = arr[i] - q[i][i+1];
flag = !flag;
}
}
ll mini = 1e9;
ll dif = 0;
for(int i = 1; i<=n; i++)
mini = min(mini, arr[i]);
dif = 1 - mini;
for(int i = 1; i<=n; i++)
arr[i]+=dif;
for(int i = 1; i<=n; i++)
answer(i, arr[i]);
return;
}
for(int i = 1; i<=n; i++)
answer(i, arr[i]);
return;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |