제출 #102469

#제출 시각아이디문제언어결과실행 시간메모리
102469IOrtroiiiXylophone (JOI18_xylophone)C++14
100 / 100
91 ms576 KiB
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;

const int N = 5050;

int a[N];
int p[N];

void solve(int n) {
	if (n == 1) {
		answer(1, 1);
	}
	a[1] = 0;
	a[2] = query(1, 2);
	for (int i = 3; i <= n; ++i) {
		int u = query(i - 1, i), v = query(i - 2, i);
		if (a[i - 1] < a[i - 2]) {
			if (v == u + a[i - 2] - a[i - 1]) {
				a[i] = a[i - 1] - u;
			} else {
				a[i] = a[i - 1] + u;
			}
		} else {
			if (v == u + a[i - 1] - a[i - 2]) {
				a[i] = a[i - 1] + u;
			} else {
				a[i] = a[i - 1] - u;
			}
		}
	}
	int val = *min_element(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i) {
		a[i] += (1 - val);
		p[a[i]] = i;
	}
	if (p[1] > p[n]) {
		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...