제출 #145451

#제출 시각아이디문제언어결과실행 시간메모리
145451faremyXylophone (JOI18_xylophone)C++14
100 / 100
147 ms508 KiB
#include "xylophone.h"


static int A[5000];

const int MAXN = 5e3;

int diff[MAXN];
int direction[MAXN];
int relAns[MAXN];


void solve(int N)
{
	for (int i = 1; i < N; i++)
		diff[i - 1] = query(i, i + 1);

	direction[0] = 1;
	for (int i = 2; i < N; i++)
	{
		direction[i - 1] = direction[i - 2];
		if (query(i - 1, i + 1) != diff[i - 2] + diff[i - 1])
			direction[i - 1] *= -1;
	}

	int posMin = 0, posMax = 0;
	for (int i = 1; i < N; i++)
	{
		relAns[i] = relAns[i - 1] + diff[i - 1] * direction[i - 1];
		if (relAns[i] < relAns[posMin])
			posMin = i;
		if (relAns[i] > relAns[posMax])
			posMax = i;
	}
	
	if (posMax < posMin)
	{
		posMin = posMax;
		for (int i = 1; i < N; i++)
			relAns[i] *= -1;
	}

	for (int i = 0; i < N; i++)
		answer(i + 1, relAns[i] - relAns[posMin] + 1);
}

컴파일 시 표준 에러 (stderr) 메시지

xylophone.cpp:4:12: warning: 'A' defined but not used [-Wunused-variable]
 static int A[5000];
            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...