제출 #763202

#제출 시각아이디문제언어결과실행 시간메모리
763202vjudge1Xylophone (JOI18_xylophone)C++17
47 / 100
80 ms20420 KiB
#include "xylophone.h"
int q[5005][5005], a[5005];
void solve(int n) {
	for (int i = 1; i <= n-1; ++i) q[i][i+1] = q[i+1][i] = query(i, i+1);
	for (int i = 1; i <= n-2; ++i) q[i][i+2] = q[i+2][i] = query(i, i+2);
	int pos = 1;
	for (int i = 1<<12; i > 0; i >>= 1) {
		if (pos + i > n) continue;
		if (query(pos + i, n) == n - 1) pos += i;
	}
	a[pos] = 1;
	if (pos < n) a[pos+1] = q[pos][pos+1] + 1;
	if (pos > 1) a[pos-1] = q[pos][pos-1] + 1;
	for (int i = pos + 2; i <= n; ++i) {
		if (q[i-2][i-1] + q[i-1][i] == q[i-2][i]) {
			if (a[i-2] > a[i-1]) a[i] = a[i-1] - q[i-1][i];
			else a[i] = a[i-1] + q[i-1][i];
		} else {
			if (a[i-2] > a[i-1]) a[i] = a[i-1] + q[i-1][i];
			else a[i] = a[i-1] - q[i-1][i];
		}
	}
	for (int i = pos - 2; i >= 1; --i) {
		if (q[i+2][i+1] + q[i+1][i] == q[i+2][i]) {
			if (a[i+2] > a[i+1]) a[i] = a[i+1] - q[i+1][i];
			else a[i] = a[i+1] + q[i+1][i];
		} else {
			if (a[i+2] > a[i+1]) a[i] = a[i+1] + q[i+1][i];
			else a[i] = a[i+1] - q[i+1][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...