제출 #642503

#제출 시각아이디문제언어결과실행 시간메모리
642503kausarmeXylophone (JOI18_xylophone)C++14
0 / 100
0 ms300 KiB
#include<bits/stdc++.h>
#include "xylophone.h"
using namespace std;


static int ans[5005];
static int diff[5005];
static int diff2[5005];
static bool naik[5005];
 //diff(i)= abs(A[i] - A[i+1]) 
void solve(int N) {
	for(int i = 1; i <= N - 1; i++){
		diff[i] = query(i,i+1);
	}
	for (int i = 1; i <= N -2; ++i){
		diff2[i] = query(i,i+2);
	}

	naik[0] = 0;
	for (int i = 1; i <= N-2; ++i)
	{
		if(diff2[i] == diff[i] + diff[i+1]){
			naik[i] = naik[i-1];
		} else{
			naik[i]= !naik[i-1];
		}
	}

	ans[0] = 0;
	for (int i = 1; i <= N; ++i){
		if(naik[i])ans[i+1] = ans[i] + diff[i];
		else ans[i+1] = ans[i] - diff[i];
	}

	int mins = ans[1];
	for (int i = 1; i <= N; ++i){
		mins = min(ans[i],mins);
	}

	for (int i = 1; i <= N; ++i){
		ans[i] += mins;
	}

	for(int i = 1; i <= N; i++) {
		answer(i,ans[i]);
	}
}


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