Submission #97223

#TimeUsernameProblemLanguageResultExecution timeMemory
97223diamond_dukeXylophone (JOI18_xylophone)C++11
100 / 100
111 ms580 KiB
#include "xylophone.h"
#include <algorithm>
int arr[5005], two[5005], three[5005];
void solve(int n)
{
	for (int i = 1; i < n; i++)
		two[i] = query(i, i + 1);
	for (int i = 2; i < n; i++)
		three[i] = query(i - 1, i + 1);
	arr[0] = 0;
	arr[1] = two[1];
	for (int i = 1, d = 1; i < n; i++)
	{
		d ^= three[i] != two[i] + two[i - 1];
		arr[i] = arr[i - 1] + two[i] * (d * 2 - 1);
	}
	int mn = std::min_element(arr, arr + n) - arr,
		mx = std::max_element(arr, arr + n) - arr;
	for (int i = 0; i < n; i++)
		answer(i + 1, mn < mx ? arr[i] - arr[mn] + 1 : arr[mx] - arr[i] + 1);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...