Submission #953703

# Submission time Handle Problem Language Result Execution time Memory
953703 2024-03-26T13:50:55 Z wood Xylophone (JOI18_xylophone) C++17
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>  
#include "xylophone.h";
using namespace std;
 
typedef long long ll;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MOD %1000000007

//int query(int s, int t);
void solve(int n){
	int res[n]; memset(res,0,sizeof res);
	int l = 0, r = n;
	while(r-l>1){
		int mid = (l+r)/2;
		int x = query(1,mid);
		if(x<n) l = mid;
		else r = mid;
	}
	int R = l;
	l = 0, r = n;
	while(r-l>1){
		int mid = (l+r)/2;
		int x = query(mid,n);
		if(x<n-1) r = mid;
		else l = mid;
	}
	int L = l-1;
	res[l] = 1;
	res[R]=n;//replace w R
	if(l)
	res[l-1] = query(l-1,l)+1;
	res[l+1] = query(l,l+1)+1;
	for (int i = l - 1; i >= 0; i--)
	{
		int q = query(i,i+1);
		if(res[i+1]+q>n)
			res[i]=res[i+1]-q;
		else if(res[i+1]-q<1)
			res[i] = res[i+1] + q;
		else{
			int q2 = query(i,i+2);
			if((q2>abs(res[i+2]-res[i+1])&&res[i+2]>res[i+1])||(q2<abs(res[i+2]-res[i+1])&&res[i+2]<res[i+1]))
				res[i]=res[i+2]-q2;
			else
				res[i]=res[i+2]+q2;
		}
	}
	for (size_t i = l+1; i <= n; i++)
	{
		int q = query(i,i+1);
		if(res[i-1]+q>n)
			res[i]=res[i-1]-q;
		else if(res[i-1]-q<1)
			res[i] = res[i-1] + q;
		else{
			int q2 = query(i-1,i+1);
			if((q2>abs(res[i-2]-res[i-1])&&res[i-2]>res[i-1])||(q2<abs(res[i-2]-res[i-1])&&res[i-2]<res[i-1]))
				res[i]=res[i-2]-q2;
			else
				res[i]=res[i-2]+q2;
		}
	}
}

Compilation message

xylophone.cpp:2:23: warning: extra tokens at end of #include directive
    2 | #include "xylophone.h";
      |                       ^
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:54:25: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |  for (size_t i = l+1; i <= n; i++)
      |                       ~~^~~~
xylophone.cpp:33:6: warning: unused variable 'L' [-Wunused-variable]
   33 |  int L = l-1;
      |      ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -