제출 #881903

#제출 시각아이디문제언어결과실행 시간메모리
881903elisaipateXylophone (JOI18_xylophone)C++14
100 / 100
60 ms1548 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...