제출 #1347398

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

using namespace std;

void solve(int n) {
	vector <int> a(n + 1);
	a[1] = 0;
	a[2] = query(1, 2);
	for (int i = 3; i <= n; i++) {
		int val = query(i - 1, i);
		int pval = query(i - 2, i);
		if (pval == abs(a[i - 1] - a[i - 2])) {
			if (a[i - 1] > a[i - 2]) a[i] = a[i - 1] - val;
			else a[i] = a[i - 1] + val;
		}
		else {
			if (pval == val) {
				if (a[i - 1] > a[i - 2]) a[i] = a[i - 1] - val;
				else a[i] = a[i - 1] + val;
			}
			else {
				if (a[i - 1] > a[i - 2]) a[i] = a[i - 1] + val;
				else a[i] = a[i - 1] - val;
			}
		}
	}
	int mn = 1e9;
	for (int i = 1; i <= n; i++) mn = min(mn, a[i]);
	if (mn <= 0) mn *= -1, mn++;
	for (int i = 1; i <= n; i++) a[i] += mn;
	bool wrong = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] == n) {
			wrong = 1;
			break;
		}
		if (a[i] == 1) break;
	}
	if (wrong) for (int i = 1; i <= n; i++) a[i] = n - a[i] + 1;
	// for (int i = 1; i <= n; i++) cout << 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...