Submission #1055914

# Submission time Handle Problem Language Result Execution time Memory
1055914 2024-08-13T06:32:35 Z tamir1 Xylophone (JOI18_xylophone) C++17
0 / 100
1 ms 344 KB
#include<bits/stdc++.h>
#include "xylophone.h"
using namespace std;
static int A[5000];
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 Incorrect 1 ms 344 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 344 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 344 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -