Submission #679580

#TimeUsernameProblemLanguageResultExecution timeMemory
679580Doncho_BonbonchoXylophone (JOI18_xylophone)C++14
100 / 100
99 ms436 KiB
#include <bits/stdc++.h>
#include "xylophone.h"

const int MAX_N = 8192;

static int a[MAX_N];

int two[MAX_N];
int tri[MAX_N];

bool otn[MAX_N]; // i and i+1
	
void solve(int n) {

	for( int i=1 ; i<n ; i++ ){
		two[i] =  query( i, i+1 );;
	}

	for( int i=1 ; i<n-1 ; i++ ){
		tri[i] =  query( i, i+2 );;
	}
	
	otn[1] = 1;
	for( int i=1 ; i<n-1; i++ ){
		if( tri[i] == two[i] + two[i+1] ) otn[i+1] = otn[i];
		else otn[i+1] = !otn[i];
	}

	int min = 1, max = 1;
	a[1] = 0;
	for( int i=1 ; i<n ; i++ ){
		if( otn[i] ) a[i+1] = a[i] - two[i];
		else a[i+1] = a[i] + two[i];

		if( a[min] > a[i] ) min = i;
		if( a[max] < a[i] ) max = i;
	}

	if( a[min] > a[n] ) min = n;
	if( a[max] < a[n] ) max = n;

	/*
	std::cerr<<" ! "<<min<<" "<<max<<" -> "<<a[min]<<" "<<a[max]<<"\n";
	for( int i=1 ; i<=n ; i++ ) std::cerr<<a[i]<<" ";
	std::cerr<<"\n";
	*/

	if( min < max ){
		for( int i=1; i<=n ; i++ ){
			answer( i, a[i] + 1 - a[min] );

		}
		return ;
	}//else std::cerr<<" ne stava \n\n\n\n ";


	min = 1, max = 1;
	a[1] = 0;
	for( int i=1 ; i<n ; i++ ){
		if( otn[i] ) a[i+1] = a[i] + two[i];
		else a[i+1] = a[i] - two[i];

		if( a[min] > a[i] ) min = i;
		if( a[max] < a[i] ) max = i;
	}

	if( a[min] > a[n] ) min = n;
	if( a[max] < a[n] ) max = n;

	/*
	for( int i=1 ; i<=n ; i++ ) std::cerr<<a[i]<<" ";
	std::cerr<<"\n";
	*/
	

	for( int i=1; i<=n ; i++ ){
		answer( i, a[i] + 1 - a[min] );
	}

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...