Submission #1272629

#TimeUsernameProblemLanguageResultExecution timeMemory
1272629sakkaXylophone (JOI18_xylophone)C++20
0 / 100
1 ms332 KiB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> diff(5005);
vector<int> ans1(5005), ans2(5005);

const int INF = 1e9;

void solve(int n) {
	for(int i=1; i<=n-1; i++){
		int d = query(i,i+1);
		diff[i+1] = d;
	}
	ans1[2] = diff[2];
	ans2[2] = -diff[2];
	for(int i=1; i<=n-2; i++){
		ans1[i+2] = ans2[i+2] = diff[i+2];
		int d2 = query(i,i+2);
		if(d2 == diff[i+1] + diff[i+2]){
			ans2[i+2] *= -1;
			// cout << "incdec  ";
		}
		else{
			ans1[i+2] *= -ans1[i+1]/abs(ans1[i+1]);
			ans2[i+2] *= -ans2[i+1]/abs(ans2[i+1]);
			// cout << "naikturun  ";
		}
	}

	for(int i=2; i<=n; i++){
		ans1[i] += ans1[i-1];
		ans2[i] += ans2[i-1];
		// cout << ans1[i] << " " << ans2[i] << endl;
	}

	int mn = INF, mx = -INF, imn = 0, imx = 0;
	for(int i=1; i<=n; i++){
		if(ans1[i] < mn){
			mn = ans1[i];
			imn = i;
		}
		if(ans1[i] > mx){
			mx = ans1[i];
			imx = i;
		}
	}

	if(imn < imx){
		// cout << "yes";
		for(int i=1; i<=n; i++){
			answer(i, ans1[i]-mn+1);
		}
	}
	else{
		// cout << "no";
		for(int i=1; i<=n; i++){
			answer(i, ans2[i]-mn+1);
		}
	}
}

// g++ -std=c++14 -O2 -pipe -static -s -o xylophone grader.cpp xylophone.cpp
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...