Submission #1290644

#TimeUsernameProblemLanguageResultExecution timeMemory
1290644azradudukalayXylophone (JOI18_xylophone)C++20
100 / 100
28 ms452 KiB
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;

static int A[5000];

void solve(int N) {
	vector<int> diff(N, 0), diff2(N-1, 0);
	for (int i = 1; i < N; ++i) diff[i] = query(i, i+1);
	for (int i = 1; i < N-1; ++i) diff2[i] = query(i, i+2);
	vector<int> sgdf(N, 0); sgdf[1] = 1;
	for (int i = 2; i < N; ++i) sgdf[i] = sgdf[i-1]*(1-2*(diff[i-1]+diff[i] > diff2[i-1]));
	for (int i = 1; i < N; ++i) sgdf[i] = diff[i]*sgdf[i]+sgdf[i-1];
	cout << '\n';
	sgdf[0] = 0;
	int mx = max_element(sgdf.begin(), sgdf.end()) - sgdf.begin(), mn = min_element(sgdf.begin(), sgdf.end()) - sgdf.begin();
	int β, σ;
	if (mx < mn) { σ = -1; β = N+sgdf[mn]; }
	else { σ = 1; β = N-sgdf[mx]; }
	for (int i = 1; i <= N; ++i) answer(i, σ*sgdf[i-1]+β);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...