답안 #960647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960647 2024-04-10T18:27:21 Z Nelt Xylophone (JOI18_xylophone) C++17
0 / 100
1 ms 432 KB
#include "xylophone.h"
#include <bits/stdc++.h>

#define ll long long
#define endl "\n"

using namespace std;
map<pair<ll, ll>, ll> mp;
ll ask(ll i, ll j)
{
	if (i > j) swap(i, j);
	return mp.count({i, j}) ? mp[{i, j}] : mp[{i, j}] = query(i, j);
}
void solve(int n) {
	ll a[n + 1];
	ll l = 1, r = n;
	while (l <= r)
	{
		ll mid = (l + r) >> 1;
		if (ask(mid, n) == n - 1)
			l = mid + 1;
		else
			r = mid - 1;
	}
	l--;
	a[l] = 1;
	if (l + 1 <= n)
		a[l + 1] = ask(l, l + 1) + 1;
	for (ll i = l + 2; i <= n; i++)
		if (a[i - 2] < a[i - 1])
		{
			if (ask(i - 2, i) > ask(i - 2, i - 1))
				a[i] = ask(i - 2, i) + a[i - 2];
			else
				a[i] = a[i - 1] - ask(i - 1, i);
		}
		else
		{
			if (ask(i - 2, i) > ask(i - 2, i - 1))
				a[i] = a[i - 2] - ask(i - 2, i);
			else
				a[i] = ask(i - 1, i) + a[i - 1];
		}
	if (l - 1 > 0)
		a[l - 1] = ask(l - 1, l) + 1;
	for (ll i = l - 2; i >= 1; i--)
		if (a[i + 2] < a[i + 1])
		{
			if (ask(i + 2, i) > ask(i + 2, i + 1))
				a[i] = ask(i + 2, i) + a[i + 2];
			else
				a[i] = a[i + 1] - ask(i, i + 1);
		}
		else
		{
			if (ask(i + 2, i) > ask(i + 2, i + 1))
				a[i] = a[i + 2] - ask(i + 2, i);
			else
				a[i] = ask(i + 1, i) + a[i + 1];
		}
	for (ll i = 1; i <= n; i++)
		answer(i, a[i]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 1 ms 432 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 1 ms 432 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 1 ms 432 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -