Submission #111324

# Submission time Handle Problem Language Result Execution time Memory
111324 2019-05-14T19:17:04 Z vex Xylophone (JOI18_xylophone) C++14
47 / 100
91 ms 428 KB
#include<bits/stdc++.h>
#include<xylophone.h>
using namespace std;
 
int a[5005];
bool bio[5005];
 
void solve(int n)
{
	int l=1;
	int r=n;
	int sol=n;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(query(1,mid)==n-1)
		{
			sol=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	
	for(int i=1;i<=n;i++)bio[i]=false;
	bio[n]=true;
	
	a[sol]=n;bio[n]=true;
	if(sol<n)a[sol+1]=n-query(sol,sol+1);
	a[sol-1]=n-query(sol-1,sol);
 
	for(int i=sol+2;i<=n;i++)
	{
		int maxx=max(a[i-1],a[i-2]);
		int minn=min(a[i-1],a[i-2]);
		int d1=query(i-2,i);
		if(d1==maxx-minn)
		{
			if(a[i-1]==maxx)a[i]=maxx-query(i-1,i);
			else a[i]=minn+query(i-1,i);
		}
		else
		{
			int br1=minn+d1;
			int br2=maxx-d1;
			if(br1>n || bio[br1])a[i]=br2;
			else if(br2<1 || bio[br2])a[i]=br1;
			else
			{
				int d2=query(i-1,i);
				int num1=a[i-1]-d2;
				int num2=a[i-1]+d2;
				
				if(num1>0 && num1<=n && (num1==br1 || num1==br2))a[i]=num1;
				else a[i]=num2;
			}
		}
		bio[a[i]]=true;
	}
	
	for(int i=sol-2;i>0;i--)
	{
		int maxx=max(a[i+1],a[i+2]);
		int minn=min(a[i+1],a[i+2]);
		int d1=query(i,i+2);
		if(d1==maxx-minn)
		{
			if(a[i+1]==maxx)a[i]=maxx-query(i,i+1);
			else a[i]=minn+query(i,i+1);
		}
		else
		{
			int br1=minn+d1;
			int br2=maxx-d1;
			if(br1>n || bio[br1])a[i]=br2;
			else if(br2<1 || bio[br2])a[i]=br1;
			else
			{
				int d2=query(i,i+1);
				int num1=a[i+1]-d2;
				int num2=a[i+1]+d2;
				
				if(num1<=n && num1>0 && (num1==br1 || num1==br2))a[i]=num1;
				else a[i]=num2;
			}
		}
		bio[a[i]]=true;
	}
	
	
	for(int i=1;i<=n;i++)answer(i,a[i]);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 328 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 408 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 328 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 3 ms 256 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 328 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 408 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 328 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 3 ms 256 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 11 ms 256 KB Output is correct
18 Correct 18 ms 304 KB Output is correct
19 Correct 8 ms 320 KB Output is correct
20 Correct 19 ms 384 KB Output is correct
21 Correct 20 ms 384 KB Output is correct
22 Correct 12 ms 328 KB Output is correct
23 Correct 13 ms 384 KB Output is correct
24 Correct 26 ms 256 KB Output is correct
25 Correct 14 ms 256 KB Output is correct
26 Correct 22 ms 256 KB Output is correct
27 Correct 17 ms 384 KB Output is correct
28 Correct 9 ms 428 KB Output is correct
29 Correct 14 ms 256 KB Output is correct
30 Correct 16 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 328 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 408 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 328 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 3 ms 256 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 11 ms 256 KB Output is correct
18 Correct 18 ms 304 KB Output is correct
19 Correct 8 ms 320 KB Output is correct
20 Correct 19 ms 384 KB Output is correct
21 Correct 20 ms 384 KB Output is correct
22 Correct 12 ms 328 KB Output is correct
23 Correct 13 ms 384 KB Output is correct
24 Correct 26 ms 256 KB Output is correct
25 Correct 14 ms 256 KB Output is correct
26 Correct 22 ms 256 KB Output is correct
27 Correct 17 ms 384 KB Output is correct
28 Correct 9 ms 428 KB Output is correct
29 Correct 14 ms 256 KB Output is correct
30 Correct 16 ms 256 KB Output is correct
31 Correct 36 ms 424 KB Output is correct
32 Correct 37 ms 384 KB Output is correct
33 Correct 50 ms 376 KB Output is correct
34 Correct 81 ms 256 KB Output is correct
35 Correct 75 ms 384 KB Output is correct
36 Correct 56 ms 324 KB Output is correct
37 Incorrect 91 ms 332 KB Wrong Answer [2]
38 Halted 0 ms 0 KB -