Submission #642951

#TimeUsernameProblemLanguageResultExecution timeMemory
642951amukkalirXylophone (JOI18_xylophone)C++17
100 / 100
107 ms544 KiB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std; 

static int A[5005];
int dif[5005]; 

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

	int sgn = -1; 
	int mn = 0; 
	for(int i=2; i<=N; i++) {
		int tes = 0;
		if(i>2) tes = query(i-2, i); 
		if (tes != dif[i] + dif[i-1]) sgn *= -1; 
		A[i] = A[i-1] + sgn*dif[i]; 		
		mn = min(mn, A[i]); 
	}

	int p1 = 0, pn = 0; 
	for(int i=1; i<=N; i++) {
		A[i] -= (mn-1); 
		if(A[i]==1) p1=i;
		if(A[i]==N) pn=i; 
	}
	
	if (pn < p1)
		for (int i=1; i<=N; i++) A[i] = N+1-A[i];
	
	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...