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 <iostream>
#include "xylophone.h"
using namespace std;
#define nmax 5000
int v2[nmax], v3[nmax], semn[nmax], nr[nmax];
void solve( int n ) {
int i, x = 0, minn = 0, pozmin = 1, maxx = 0, pozmax = 1, t, aux;
for( i = 1; i < n; i++ )
v2[i] = query( i, i + 1 );
for( i = 1; i < n - 1; i++ )
v3[i] = query( i, i + 2 );
semn[1] = 1;
for( i = 1; i < n - 1; i++ ) {
if( v3[i] == v2[i] + v2[i + 1] )
semn[i+1] = semn[i];
else
semn[i+1] = - semn[i];
}
for( i = 2; i <= n; i++ ) {
x = x + v2[i-1] * semn[i-1];
//cout << x << " ";
if( x < minn ) {
minn = x;
pozmin = i;
} else if( x > maxx ) {
maxx = x;
pozmax = i;
}
}
//cout << "\n";
t = 1;
if( pozmin > pozmax ) {
t = -1;
aux = pozmin;
pozmin = pozmax;
pozmax = aux;
}
nr[pozmin] = 1;
for( i = pozmin + 1; i <= n; i++ )
nr[i] = nr[i-1] + v2[i-1] * t * semn[i-1];
for( i = pozmin - 1; i >= 1; i-- )
nr[i] = nr[i+1] - v2[i] * t * semn[i];
/*for( i = 1; i <= n; i++ )
cout << semn[i] << " ";
cout << "\n";
cout << pozmin << " " << pozmax;
cout << "\n";*/
for( i = 1; i <= n; i++ )
answer( i, nr[i] );
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |