이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
void solve(int n)
{
int ans[5001] , pre_query[5001][5001] , found[9999] , one , l = 1 , r = n-1 , m ;
while(l<=r)
{
m = (l+r)/2 ;
pre_query[m][n] = query(m,n) ;
if ( pre_query[m][n] == n-1 ) l = m+1 ;
else r = m-1 ;
}
one = r ;
ans[one] = found[1] = 1 ;
for ( int i = one+1 ; i <= n ; i++ )
{
int x , y ;
x = pre_query[i-1][i] = query(i-1,i) ;
if ( ans[i-1]+x > n || found[ans[i-1]+x] == 1 ) ans[i] = ans[i-1]-x ;
else if ( ans[i-1]-x <= 1 || found[ans[i-1]-x] == 1 ) ans[i] = ans[i-1]+x ;
else
{
y = pre_query[i-2][i] = query(i-2,i) ;
if ( ans[i-1] > ans[i-2] )
{
if ( y == pre_query[i-2][i-1] || y == x ) ans[i] = ans[i-1]-x ;
else ans[i] = ans[i-1]+x ;
}
else
{
if ( y == pre_query[i-2][i-1] || y == x ) ans[i] = ans[i-1]+x ;
else ans[i] = ans[i-1]-x ;
}
}
found[ans[i]] = 1 ;
}
for ( int i = one-1 ; i >= 1 ; i-- )
{
int x , y ;
x = pre_query[i][i+1] = query(i,i+1) ;
if ( ans[i+1]+x > n || found[ans[i+1]+x] == 1 ) ans[i] = ans[i+1]-x ;
else if ( ans[i+1]-x <= 1 || found[ans[i+1]-x] == 1 ) ans[i] = ans[i+1]+x ;
else
{
y = pre_query[i][i+2] = query(i,i+2) ;
if ( ans[i+1] > ans[i+2] )
{
if ( y == pre_query[i+1][i+2] || y == x ) ans[i] = ans[i+1]-x ;
else ans[i] = ans[i+1]+x ;
}
else
{
if ( y == pre_query[i+1][i+2] || y == x ) ans[i] = ans[i+1]+x ;
else ans[i] = ans[i+1]-x ;
}
}
found[ans[i]] = 1 ;
}
for ( int i = 1 ; i <= n ; i++ ) answer(i,ans[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... |