제출 #1349411

#제출 시각아이디문제언어결과실행 시간메모리
1349411winXylophone (JOI18_xylophone)C++20
47 / 100
11 ms592 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;
		a2[a[i]] = i;
		mn = min(mn,a[i]);
	}
	if (a2[1+mn-1] < a2[n+mn-1]) {
		for (int i = 1; i <= n; i++) {
			// dbg("1",i,a[i]-mn+1);
			answer(i,a[i]-mn+1);
		}
		return;
	}
	now = -1;
	mn = 2e9;
	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...