Submission #1255868

#TimeUsernameProblemLanguageResultExecution timeMemory
1255868inkvizytorXylophone (JOI18_xylophone)C++20
100 / 100
26 ms512 KiB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

static int A[5000];

void solve(int n) {
	vector<int> p1 (n, 0), p2 (n, 0);
	vector<int> z (n, 1);
	for (int i = 0; i < n-1; i++) {
		p1[i] = query(i+1, i+2);
	}
	for (int i = 0; i < n-2; i++) {
		p2[i] = query(i+1, i+3);
	}
	for (int i = 1; i < n-1; i++) {
		if (p1[i-1]+p1[i]!=p2[i-1]) {
			z[i] = -z[i-1];
		}
		else {
			z[i] = z[i-1];
		}
	}
	vector<pair<int, int>> s (n, {0, 0});
	for (int i = 1; i < n; i++) {
		s[i].first = s[i-1].first+z[i-1]*p1[i-1];
		s[i].second = i;
	}
	sort(s.begin(), s.end());
	if (s[0].second > s[n-1].second) {
		reverse(s.begin(), s.end());
	}
	for (int i = 0; i < n; i++) {
		answer(s[i].second+1, i+1);
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...