Submission #146230

#TimeUsernameProblemLanguageResultExecution timeMemory
146230DiuvenXylophone (JOI18_xylophone)C++14
100 / 100
123 ms504 KiB
#include "xylophone.h"
#include <algorithm>
#include <iostream>
using namespace std;

static int P[5001], A[5001];

void solve(int n){
	for(int i=2; i<=n; i++) P[i] = query(i-1, i);

	A[1] = 0; A[2] = P[2];

	for(int i=3; i<=n; i++){
		int x = query(i-2, i);
		int sg = A[i-1]>A[i-2] ? 1 : -1;
		if(x!=P[i-1]+P[i]) sg *= -1;
		A[i] = A[i-1] + sg*P[i];
	}

	int m = *min_element(A+1, A+n+1);
	for(int i=1; i<=n; i++) A[i] -= m-1;
	int x=-1, y=-1;
	for(int i=1; i<=n; i++) if(A[i]==1) x=i; else if(A[i]==n) y=i;
	if(x>y) for(int i=1; i<=n; i++) A[i] = n-A[i]+1;

	for(int i=1; i<=n; i++) answer(i, A[i]);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...