Submission #285756

# Submission time Handle Problem Language Result Execution time Memory
285756 2020-08-29T14:41:55 Z Pyqe Xylophone (JOI18_xylophone) C++14
100 / 100
75 ms 632 KB
#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;

long long n,sq[5069];
bitset<5069> vtd;

bool vld(long long x)
{
	return x>0&&x<=n&&!vtd[x];
}

void fl(long long lh,long long rh,long long u)
{
	long long i,k,l;
	
	for(i=lh;i!=rh+u;i+=u)
	{
		k=query(min(i,i-u),max(i,i-u));
		if(!vld(sq[i-u]-k))
		{
			sq[i]=sq[i-u]+k;
		}
		else if(!vld(sq[i-u]+k))
		{
			sq[i]=sq[i-u]-k;
		}
		else
		{
			l=query(min(i,i-u*2),max(i,i-u*2));
			if(max(sq[i-u]+k,sq[i-u*2])-min(sq[i-u],sq[i-u*2])==l)
			{
				sq[i]=sq[i-u]+k;
			}
			else
			{
				sq[i]=sq[i-u]-k;
			}
		}
		vtd[sq[i]]=1;
	}
}

void solve(int on)
{
	long long i,lh,rh,md,zz,st,fn;
	
	n=on;
	zz=1;
	for(lh=2,rh=n-1;lh<=rh;)
	{
		md=(lh+rh)/2;
		if(query(md,n)==n-1)
		{
			zz=md;
			lh=md+1;
		}
		else
		{
			rh=md-1;
		}
	}
	st=zz;
	sq[st]=1;
	vtd[1]=1;
	zz=n;
	for(lh=st+1,rh=n-1;lh<=rh;)
	{
		md=(lh+rh)/2;
		if(query(1,md)==n-1)
		{
			zz=md;
			rh=md-1;
		}
		else
		{
			lh=md+1;
		}
	}
	fn=zz;
	sq[fn]=n;
	vtd[n]=1;
	fl(st-1,1,-1);
	fl(st+1,fn-1,1);
	fl(fn+1,n,1);
	for(i=1;i<=n;i++)
	{
		answer(i,sq[i]);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 4 ms 256 KB Output is correct
17 Correct 8 ms 256 KB Output is correct
18 Correct 11 ms 384 KB Output is correct
19 Correct 16 ms 376 KB Output is correct
20 Correct 13 ms 384 KB Output is correct
21 Correct 15 ms 376 KB Output is correct
22 Correct 16 ms 384 KB Output is correct
23 Correct 10 ms 384 KB Output is correct
24 Correct 13 ms 384 KB Output is correct
25 Correct 12 ms 384 KB Output is correct
26 Correct 7 ms 376 KB Output is correct
27 Correct 10 ms 256 KB Output is correct
28 Correct 20 ms 380 KB Output is correct
29 Correct 17 ms 256 KB Output is correct
30 Correct 16 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 4 ms 256 KB Output is correct
17 Correct 8 ms 256 KB Output is correct
18 Correct 11 ms 384 KB Output is correct
19 Correct 16 ms 376 KB Output is correct
20 Correct 13 ms 384 KB Output is correct
21 Correct 15 ms 376 KB Output is correct
22 Correct 16 ms 384 KB Output is correct
23 Correct 10 ms 384 KB Output is correct
24 Correct 13 ms 384 KB Output is correct
25 Correct 12 ms 384 KB Output is correct
26 Correct 7 ms 376 KB Output is correct
27 Correct 10 ms 256 KB Output is correct
28 Correct 20 ms 380 KB Output is correct
29 Correct 17 ms 256 KB Output is correct
30 Correct 16 ms 384 KB Output is correct
31 Correct 16 ms 388 KB Output is correct
32 Correct 33 ms 504 KB Output is correct
33 Correct 51 ms 392 KB Output is correct
34 Correct 58 ms 504 KB Output is correct
35 Correct 55 ms 384 KB Output is correct
36 Correct 44 ms 384 KB Output is correct
37 Correct 50 ms 384 KB Output is correct
38 Correct 43 ms 504 KB Output is correct
39 Correct 75 ms 384 KB Output is correct
40 Correct 61 ms 384 KB Output is correct
41 Correct 61 ms 384 KB Output is correct
42 Correct 50 ms 504 KB Output is correct
43 Correct 47 ms 384 KB Output is correct
44 Correct 30 ms 500 KB Output is correct
45 Correct 60 ms 384 KB Output is correct
46 Correct 63 ms 632 KB Output is correct
47 Correct 58 ms 376 KB Output is correct
48 Correct 65 ms 504 KB Output is correct
49 Correct 72 ms 400 KB Output is correct
50 Correct 62 ms 512 KB Output is correct
51 Correct 54 ms 504 KB Output is correct
52 Correct 65 ms 496 KB Output is correct
53 Correct 57 ms 384 KB Output is correct
54 Correct 57 ms 504 KB Output is correct
55 Correct 52 ms 384 KB Output is correct
56 Correct 55 ms 384 KB Output is correct
57 Correct 58 ms 384 KB Output is correct
58 Correct 60 ms 504 KB Output is correct
59 Correct 55 ms 400 KB Output is correct
60 Correct 51 ms 384 KB Output is correct