Submission #71687

# Submission time Handle Problem Language Result Execution time Memory
71687 2018-08-25T11:19:59 Z jibu11 Xylophone (JOI18_xylophone) C++14
100 / 100
93 ms 840 KB
#include "xylophone.h"
#include <stdio.h>
//static int A[5000];
int lis[5010], vis[5010];

int bs(int in, int fin, int vl)
{
	if(in >= fin)
		return in;
	int med = (in+fin)/2;
	if(query(1,med) == vl)
		return bs(in, med, vl);
	return bs(med+1, fin, vl);
}

int abs(int a)
{
	return (a > 0) ? a : (-a);
}

void coisoetal(int pos, int dir, int n)
{
	int i;
	for(i = pos+2*dir; i <= n && i >= 1; i+=dir)
	{
		int a2;
		if(dir > 0)
			a2 = query(i-dir, i);
		else
			a2 = query(i, i-dir);
		if(lis[i-dir]+a2 > n || vis[lis[i-dir]+a2])
		{
			lis[i] = lis[i-dir]-a2;
			vis[lis[i]] = 1;
		}
		else if(lis[i-dir]-a2 < 1 || vis[lis[i-dir]-a2])
		{
			lis[i] = lis[i-dir]+a2;
			vis[lis[i]] = 1;
		}
		else
		{
			int a3;
			if(dir > 0)
				a3 = query(i-2*dir, i);
			else
				a3 = query(i, i-2*dir);
			if(a3 == abs(lis[i-dir]-lis[i-2*dir]))
			{
				if(lis[i-dir] > lis[i-2*dir])
				{
					lis[i] = lis[i-dir]-a2;
					vis[lis[i]] = 1;
				}
				else
				{
					lis[i] = lis[i-dir]+a2;
					vis[lis[i]] = 1;
				}
			}
			else if(a2 == a3)
			{
				if(lis[i-dir] > lis[i-2*dir])
				{
					lis[i] = lis[i-dir]-a2;
					vis[lis[i]] = 1;
				}
				else
				{
					lis[i] = lis[i-dir]+a2;
					vis[lis[i]] = 1;
				}
			}
			else
			{
				if(a3+lis[i-2*dir] == lis[i-dir]+a2)
				{
					lis[i] = a3+lis[i-2*dir];
					vis[lis[i]] = 1;
				}
				else
				{
					lis[i] = lis[i-2*dir]-a3;
					vis[lis[i]] = 1;
				}
			}
		}
	}
}

void solve(int n) {
	int pos = bs(1,n, n-1);
	vis[n] = 1;
	lis[pos] = n;
	if(pos != n)
	{
		int a1 = query(pos, pos+1);
		lis[pos+1] = n-a1;
		vis[n-a1] = 1;
	}
	
	int a1 = query(pos-1, pos);
	lis[pos-1] = n-a1;
	vis[n-a1] = 1;
	coisoetal(pos, 1, n);
	coisoetal(pos, -1, n);
	int i;
	for(i = 1; i <= n; i++)
	{
		//printf("%d %d\n", i, lis[i]);
		answer(i, lis[i]);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 372 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 420 KB Output is correct
5 Correct 4 ms 572 KB Output is correct
6 Correct 2 ms 572 KB Output is correct
7 Correct 3 ms 572 KB Output is correct
8 Correct 5 ms 572 KB Output is correct
9 Correct 3 ms 572 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 3 ms 572 KB Output is correct
12 Correct 2 ms 572 KB Output is correct
13 Correct 3 ms 572 KB Output is correct
14 Correct 6 ms 572 KB Output is correct
15 Correct 5 ms 572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 372 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 420 KB Output is correct
5 Correct 4 ms 572 KB Output is correct
6 Correct 2 ms 572 KB Output is correct
7 Correct 3 ms 572 KB Output is correct
8 Correct 5 ms 572 KB Output is correct
9 Correct 3 ms 572 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 3 ms 572 KB Output is correct
12 Correct 2 ms 572 KB Output is correct
13 Correct 3 ms 572 KB Output is correct
14 Correct 6 ms 572 KB Output is correct
15 Correct 5 ms 572 KB Output is correct
16 Correct 4 ms 572 KB Output is correct
17 Correct 5 ms 572 KB Output is correct
18 Correct 13 ms 572 KB Output is correct
19 Correct 7 ms 572 KB Output is correct
20 Correct 17 ms 572 KB Output is correct
21 Correct 21 ms 572 KB Output is correct
22 Correct 19 ms 572 KB Output is correct
23 Correct 20 ms 572 KB Output is correct
24 Correct 16 ms 572 KB Output is correct
25 Correct 18 ms 572 KB Output is correct
26 Correct 9 ms 572 KB Output is correct
27 Correct 19 ms 572 KB Output is correct
28 Correct 13 ms 584 KB Output is correct
29 Correct 27 ms 584 KB Output is correct
30 Correct 20 ms 584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 372 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 420 KB Output is correct
5 Correct 4 ms 572 KB Output is correct
6 Correct 2 ms 572 KB Output is correct
7 Correct 3 ms 572 KB Output is correct
8 Correct 5 ms 572 KB Output is correct
9 Correct 3 ms 572 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 3 ms 572 KB Output is correct
12 Correct 2 ms 572 KB Output is correct
13 Correct 3 ms 572 KB Output is correct
14 Correct 6 ms 572 KB Output is correct
15 Correct 5 ms 572 KB Output is correct
16 Correct 4 ms 572 KB Output is correct
17 Correct 5 ms 572 KB Output is correct
18 Correct 13 ms 572 KB Output is correct
19 Correct 7 ms 572 KB Output is correct
20 Correct 17 ms 572 KB Output is correct
21 Correct 21 ms 572 KB Output is correct
22 Correct 19 ms 572 KB Output is correct
23 Correct 20 ms 572 KB Output is correct
24 Correct 16 ms 572 KB Output is correct
25 Correct 18 ms 572 KB Output is correct
26 Correct 9 ms 572 KB Output is correct
27 Correct 19 ms 572 KB Output is correct
28 Correct 13 ms 584 KB Output is correct
29 Correct 27 ms 584 KB Output is correct
30 Correct 20 ms 584 KB Output is correct
31 Correct 31 ms 584 KB Output is correct
32 Correct 39 ms 584 KB Output is correct
33 Correct 46 ms 584 KB Output is correct
34 Correct 39 ms 672 KB Output is correct
35 Correct 69 ms 672 KB Output is correct
36 Correct 23 ms 672 KB Output is correct
37 Correct 46 ms 672 KB Output is correct
38 Correct 24 ms 672 KB Output is correct
39 Correct 63 ms 700 KB Output is correct
40 Correct 69 ms 700 KB Output is correct
41 Correct 60 ms 700 KB Output is correct
42 Correct 22 ms 700 KB Output is correct
43 Correct 58 ms 700 KB Output is correct
44 Correct 56 ms 840 KB Output is correct
45 Correct 55 ms 840 KB Output is correct
46 Correct 54 ms 840 KB Output is correct
47 Correct 68 ms 840 KB Output is correct
48 Correct 31 ms 840 KB Output is correct
49 Correct 56 ms 840 KB Output is correct
50 Correct 50 ms 840 KB Output is correct
51 Correct 75 ms 840 KB Output is correct
52 Correct 86 ms 840 KB Output is correct
53 Correct 93 ms 840 KB Output is correct
54 Correct 35 ms 840 KB Output is correct
55 Correct 72 ms 840 KB Output is correct
56 Correct 56 ms 840 KB Output is correct
57 Correct 76 ms 840 KB Output is correct
58 Correct 83 ms 840 KB Output is correct
59 Correct 81 ms 840 KB Output is correct
60 Correct 63 ms 840 KB Output is correct