Submission #1184599

#TimeUsernameProblemLanguageResultExecution timeMemory
1184599petezaXylophone (JOI18_xylophone)C++20
100 / 100
26 ms416 KiB
#include "xylophone.h"
#define max(a, b) ((a) > (b) ? (a) : (b))

static int A[5005];

void solve(int N) {
	A[0] = 1;
	A[1] = 1 + query(1, 2);
	for(int i=2;i<N;i++) {
		int r1 = query(i-1, i+1), r2 = query(i, i+1);
		if(max(A[i-1] - A[i-2], A[i-2] - A[i-1]) == r1) {
			if(A[i-2] < A[i-1]) A[i] = A[i-1] - r2;
			else A[i] = A[i-1] + r2;
		} else if(r1 == r2) {
			//op dir
			if(A[i-2] < A[i-1]) A[i] = A[i-1] - r2;
			else A[i] = A[i-1] + r2;
		} else {
			if(A[i-2] < A[i-1]) A[i] = A[i-1] + r2;
			else A[i] = A[i-1] - r2;
		}
	}
	int cmn = 10000;
	for(int i=0;i<N;i++) cmn = -max(-cmn, -A[i]);
	for(int i=0;i<N;i++) A[i] -= (cmn-1);
	int posn, pos1;
	for(int i=0;i<N;i++) {
		if(A[i] == N) posn = i;
		if(A[i] == 1) pos1 = i;
	}
	if(posn < pos1) {
		for(int i=0;i<N;i++) A[i] = (N-A[i]) + 1;
	}
	for(int i=0;i<N;i++) answer(i+1, A[i]);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...