Submission #1055967

# Submission time Handle Problem Language Result Execution time Memory
1055967 2024-08-13T06:51:54 Z tamir1 Xylophone (JOI18_xylophone) C++17
47 / 100
34 ms 712 KB
#include<bits/stdc++.h>
#include "xylophone.h"
using namespace std;
static int A[5001];
int x[5001],y[5001];
void solve(int N) {
	int l=1,r=N,mid,i,mx=1,idx=0;
	while(r>l){
		mid=(r+l+1)/2;
		if(query(mid,N)==N-1) l=mid;
		else r=mid-1;
	}
	A[l]=1;
	for(i=2;i<=N;i++) x[i]=query(i-1,i);
	for(i=3;i<=N;i++) y[i]=query(i-2,i);
	if(l<N) A[l+1]=x[l+1]+1;
	for(i=l+2;i<=N;i++){
		if(x[i-1]==y[i]){
			if(A[i-1]>A[i-2]) A[i]=A[i-1]-x[i];
			else A[i]=A[i-1]+x[i];
		}
		else{
			if(y[i]!=x[i]){
				if(A[i-1]>A[i-2]) A[i]=A[i-1]+x[i];
				else A[i]=A[i-1]-x[i];
			}
			else{
				if(A[i-2]>A[i-1]) A[i]=A[i-1]+x[i];
				else A[i]=A[i-1]-x[i];
			}
		}
	}
	if(l>1) A[l-1]=x[l]+1;
	for(i=l-2;i>=1;i--){
		if(x[i+2]==y[i+2]){
			if(A[i+1]>A[i+2]) A[i]=A[i+1]-x[i+1];
			else A[i]=A[i+1]+x[i+1];
		}
		else{
			if(y[i+2]!=x[i+1]){
				if(A[i+1]>A[i+2]) A[i]=A[i+1]+x[i+1];
				else A[i]=A[i+1]-x[i+1];
			}
			else{
				if(A[i+2]>A[i+1]) A[i]=A[i+1]+x[i+1];
				else A[i]=A[i+1]-x[i+1];
			}
		}
	}
	for(i=1;i<=N;i++){
		answer(i,A[i]);
	}
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:7:20: warning: unused variable 'mx' [-Wunused-variable]
    7 |  int l=1,r=N,mid,i,mx=1,idx=0;
      |                    ^~
xylophone.cpp:7:25: warning: unused variable 'idx' [-Wunused-variable]
    7 |  int l=1,r=N,mid,i,mx=1,idx=0;
      |                         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 420 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 420 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 9 ms 344 KB Output is correct
20 Correct 9 ms 452 KB Output is correct
21 Correct 7 ms 452 KB Output is correct
22 Correct 8 ms 712 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 7 ms 448 KB Output is correct
25 Correct 7 ms 452 KB Output is correct
26 Correct 7 ms 344 KB Output is correct
27 Correct 11 ms 344 KB Output is correct
28 Correct 8 ms 604 KB Output is correct
29 Correct 8 ms 444 KB Output is correct
30 Correct 7 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 420 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 9 ms 344 KB Output is correct
20 Correct 9 ms 452 KB Output is correct
21 Correct 7 ms 452 KB Output is correct
22 Correct 8 ms 712 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 7 ms 448 KB Output is correct
25 Correct 7 ms 452 KB Output is correct
26 Correct 7 ms 344 KB Output is correct
27 Correct 11 ms 344 KB Output is correct
28 Correct 8 ms 604 KB Output is correct
29 Correct 8 ms 444 KB Output is correct
30 Correct 7 ms 344 KB Output is correct
31 Correct 21 ms 440 KB Output is correct
32 Correct 17 ms 696 KB Output is correct
33 Correct 34 ms 344 KB Output is correct
34 Incorrect 26 ms 592 KB Wrong Answer [2]
35 Halted 0 ms 0 KB -