제출 #1349437

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

void dbg() { cout << "\n"; }
template<typename H, typename... T>
void dbg(H h, T... t) {
    cout << h << " ";
    dbg(t...);
}	

const int N = 5050;
int a[N],a2[N],d[N],d2[N],dir[N];

void solve(int n) {
	for (int i = 1; i <= n; i++) dir[i] = 1;
	for (int i = 1; i < n; i++) d[i] = query(i,i+1);
	for (int i = 1; i < n-1; i++) d2[i] = query(i,i+2);
	for (int i = 1; i < n-1; i++) {
		if (d[i]+d[i+1] == d2[i]) dir[i+2] = 1;
		else dir[i+2] = -1;
	}
	a[1] = 0;
	int now = 1;
	int mn = 0;
	for (int i = 2; i <= n; i++) {
		// dbg("dir",i,dir[i]);
		now *= dir[i];
		a[i] = a[i-1]+d[i-1]*now;
		mn = min(mn,a[i]);
	}
	bool ch = 0;
	int aidx,bidx;
	for (int i = 1; i <= n; i++) {
		if (a[i]-mn+1 == 1) aidx = i;
		else if (a[i]-mn+1 == n) bidx = i;
	}
	if (aidx < bidx) {
		for (int i = 1; i <= n; i++) {
			// dbg("1",i,a[i]-mn+1);
			answer(i,a[i]-mn+1);
		}
		return;
	}
	now = -1;
	mn = 0;
	for (int i = 2; i <= n; i++) {
		now *= dir[i];
		a[i] = a[i-1]+d[i-1]*now;
		// a2[a[i]] = i;
		mn = min(mn,a[i]);
	}
	for (int i = 1; i <= n; i++) {
		// dbg("2",i,a[i]-mn+1);
		answer(i,a[i]-mn+1);
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...