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 "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
int n;
int v[MAXN];
int ans[MAXN];
int diff[MAXN][2], t[MAXN];
int signal(int s)
{
if( s > 0 ) return 1;
return -1;
}
bool test()
{
for(int i = 1 ; i <= n ; i++)
t[i] = diff[i][0];
for(int i = 2 ; i < n ; i++)
{
t[i] = abs( t[i] );
if( diff[i - 1][0] + diff[i][0] == diff[i - 1][1] ) t[i] *= signal( t[i - 1] );
else t[i] *= signal( -t[i - 1] );
}
for(int i = 2 ; i <= n ; i++)
ans[i] = ans[i - 1] + t[i - 1];
int mn = ans[1];
for(int i = 1 ; i <= n ; i++)
mn = min( mn , ans[i] );
for(int i = 1 ; i <= n ; i++)
ans[i] += -mn + 1;
int prefixMn = n + 1;
for(int i = 1 ; i <= n ; i++)
{
if( ans[i] == n && prefixMn != 1 ) return false;
prefixMn = min( prefixMn , ans[i] );
}
for(int i = 1 ; i <= n ; i++)
answer( i , ans[i] );
return true;
}
void solve(int N)
{
n = N;
for(int i = 1 ; i + 1 <= N ; i++)
diff[i][0] = query( i , i + 1 );
for(int i = 1 ; i + 2 <= N ; i++)
diff[i][1] = query( i , i + 2 );
if( !test() )
{
diff[1][0] = -diff[1][0];
test();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |