제출 #1348641

#제출 시각아이디문제언어결과실행 시간메모리
1348641Zone_zoneeXylophone (JOI18_xylophone)C++20
100 / 100
18 ms448 KiB
#include <bits/stdc++.h>
#include "xylophone.h"

static int a[5010];

void solve(int N) {
	a[1] = 0;
	a[2] = query(1, 2); // 1
	int mn = 0;
	for(int i = 3; i <= N; ++i){ // 2*(n-3) = 2n-6
		int res = query(i-1, i);
		int tres = query(i-2, i);
		if(tres == abs(a[i-1] - a[i-2]) + res){
			if(a[i-1] > a[i-2]) a[i] = a[i-1] + res;
			else a[i] = a[i-1] - res;
		}else{
			if(a[i-1] > a[i-2]) a[i] = a[i-1] - res;
			else a[i] = a[i-1] + res;
		}
		mn = std::min(mn, a[i]);
	}
	for(int i = 1; i <= N; ++i) a[i] += -mn+1;
	bool ok = 1;
	for(int i = 1; i <= N; ++i){
		if(a[i] == N) ok = 0;
		if(a[i] == 1) break;
	}
	if(ok){
		for(int i = 1; i <= N; ++i) answer(i, a[i]);
	}else{
		for(int i = 1; i <= N; ++i) answer(i, N-a[i]+1);
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...