Submission #958310

# Submission time Handle Problem Language Result Execution time Memory
958310 2024-04-05T11:19:50 Z JwFXoiz Xylophone (JOI18_xylophone) C++14
47 / 100
125 ms 175604 KB
#include <bits/stdc++.h>
#include "xylophone.h"

using namespace std;

int a[5001], qq[5001][5001];
int C = 0;

int ask(int l, int r)
{
	assert(++C <= 10000);
	if (qq[l][r] != -1) return qq[l][r];
	return qq[l][r] = query(l, r);
}

void calc(int l, int r, int f, int up)
{
	if (r - l <= 1) return;
	if (!f)
	{
		int x = ask(l + 1, r);
		int lx = l + 1, rx = r - 1;
		while (lx < rx)
		{
			int mid = (lx + rx + 1) >> 1;
			int y = ask(mid, r);
			if (x == y) lx = mid;
			else rx = mid - 1;
		}
		if (up) a[lx] = a[r] + x;
		else a[lx] = a[r] - x;
		calc(l, lx, 0, up ^ 1), calc(lx, r, 0, up);
	}
	else
	{
		int x = ask(l, r - 1);
		int lx = l + 1, rx = r - 1;
		while (lx < rx)
		{
			int mid = (lx + rx) >> 1;
			int y = ask(l, mid);
			if (x == y) rx = mid;
			else lx = mid + 1;
		}
		if (up) a[lx] = a[l] + x;
		else a[lx] = a[l] - x;
		calc(l, lx, 1, up), calc(lx, r, 1, up ^ 1);
	}
}

void solve(int N)
{
	for (int i = 0; i <= N; i++) for (int j = 0; j <= N; j++) qq[i][j] = -1;
	int l = 1, r = N;
	while (l < r)
	{
		int mid = (l + r + 1) >> 1;
		if (ask(mid, N) == N - 1) l = mid;
		else r = mid - 1;
	}
	a[l] = 1;
	calc(0, l, 0, 1), calc(l, N + 1, 1, 1);
	for (int i = 1; i <= N; i++) 
	{
		answer(i, a[i]);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 1 ms 2532 KB Output is correct
4 Correct 2 ms 2532 KB Output is correct
5 Correct 3 ms 2788 KB Output is correct
6 Correct 1 ms 2536 KB Output is correct
7 Correct 1 ms 2532 KB Output is correct
8 Correct 2 ms 2528 KB Output is correct
9 Correct 1 ms 2536 KB Output is correct
10 Correct 3 ms 2540 KB Output is correct
11 Correct 2 ms 2536 KB Output is correct
12 Correct 2 ms 2532 KB Output is correct
13 Correct 1 ms 2536 KB Output is correct
14 Correct 2 ms 2536 KB Output is correct
15 Correct 2 ms 2536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 1 ms 2532 KB Output is correct
4 Correct 2 ms 2532 KB Output is correct
5 Correct 3 ms 2788 KB Output is correct
6 Correct 1 ms 2536 KB Output is correct
7 Correct 1 ms 2532 KB Output is correct
8 Correct 2 ms 2528 KB Output is correct
9 Correct 1 ms 2536 KB Output is correct
10 Correct 3 ms 2540 KB Output is correct
11 Correct 2 ms 2536 KB Output is correct
12 Correct 2 ms 2532 KB Output is correct
13 Correct 1 ms 2536 KB Output is correct
14 Correct 2 ms 2536 KB Output is correct
15 Correct 2 ms 2536 KB Output is correct
16 Correct 5 ms 6640 KB Output is correct
17 Correct 8 ms 10840 KB Output is correct
18 Correct 9 ms 17176 KB Output is correct
19 Correct 10 ms 21544 KB Output is correct
20 Correct 15 ms 21268 KB Output is correct
21 Correct 15 ms 21032 KB Output is correct
22 Correct 13 ms 21336 KB Output is correct
23 Correct 8 ms 21796 KB Output is correct
24 Correct 48 ms 21576 KB Output is correct
25 Correct 44 ms 21028 KB Output is correct
26 Correct 14 ms 21080 KB Output is correct
27 Correct 21 ms 21292 KB Output is correct
28 Correct 11 ms 21276 KB Output is correct
29 Correct 11 ms 21288 KB Output is correct
30 Correct 14 ms 21080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 1 ms 2532 KB Output is correct
4 Correct 2 ms 2532 KB Output is correct
5 Correct 3 ms 2788 KB Output is correct
6 Correct 1 ms 2536 KB Output is correct
7 Correct 1 ms 2532 KB Output is correct
8 Correct 2 ms 2528 KB Output is correct
9 Correct 1 ms 2536 KB Output is correct
10 Correct 3 ms 2540 KB Output is correct
11 Correct 2 ms 2536 KB Output is correct
12 Correct 2 ms 2532 KB Output is correct
13 Correct 1 ms 2536 KB Output is correct
14 Correct 2 ms 2536 KB Output is correct
15 Correct 2 ms 2536 KB Output is correct
16 Correct 5 ms 6640 KB Output is correct
17 Correct 8 ms 10840 KB Output is correct
18 Correct 9 ms 17176 KB Output is correct
19 Correct 10 ms 21544 KB Output is correct
20 Correct 15 ms 21268 KB Output is correct
21 Correct 15 ms 21032 KB Output is correct
22 Correct 13 ms 21336 KB Output is correct
23 Correct 8 ms 21796 KB Output is correct
24 Correct 48 ms 21576 KB Output is correct
25 Correct 44 ms 21028 KB Output is correct
26 Correct 14 ms 21080 KB Output is correct
27 Correct 21 ms 21292 KB Output is correct
28 Correct 11 ms 21276 KB Output is correct
29 Correct 11 ms 21288 KB Output is correct
30 Correct 14 ms 21080 KB Output is correct
31 Correct 29 ms 44156 KB Output is correct
32 Correct 37 ms 62148 KB Output is correct
33 Runtime error 125 ms 175604 KB Execution killed with signal 6
34 Halted 0 ms 0 KB -