제출 #1116609

#제출 시각아이디문제언어결과실행 시간메모리
1116609gustavo_dXylophone (JOI18_xylophone)C++17
47 / 100
182 ms588 KiB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

int a[5000];

void solve(int N) {
	int n = N;
	int pos1=n;
	for (; pos1>=1; pos1--) {
		int value = query(pos1, n);
		if (value == n-1) break;
	}
	a[pos1] = 1;
	a[pos1+1] = query(pos1, pos1+1) + 1;
	for (int pt = pos1+2; pt<=n; pt++) {
		int d1 = abs(a[pt-1] - a[pt-2]);
		int d = query(pt-1, pt);
		if (a[pt-2] < a[pt-1]) {
			if (query(pt-2, pt) == d + d1) a[pt] = a[pt-1] + d;
			else a[pt] = a[pt-1] - d;
		} else {
			if (query(pt-2, pt) == d + d1) a[pt] = a[pt-1] - d;
			else a[pt] = a[pt-1] + d;
		}
	}
	for (int pt = pos1-1; pt>=1; pt--) {
		int d1 = abs(a[pt+1] - a[pt+2]);
		int d = query(pt, pt+1);
		if (a[pt+2] < a[pt+1]) {
			if (query(pt, pt+2) == d + d1) a[pt] = a[pt+1] + d;
			else a[pt] = a[pt+1] - d;
		} else {
			if (query(pt, pt+2) == d + d1) a[pt] = a[pt+1] - d;
			else a[pt] = a[pt+1] + d;
		}
	}

	// for (int i=1; i<=n; i++) cout << a[i] << ' ';
	for(int i = 1; i <= N; i++) {
		answer(i, a[i]);
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...