Submission #704260

# Submission time Handle Problem Language Result Execution time Memory
704260 2023-03-02T02:08:34 Z anhduc2701 Xylophone (JOI18_xylophone) C++17
100 / 100
71 ms 452 KB
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include "xylophone.h"
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI 3.14159265359
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x,i) (1&((x)>>(i)))
#define MASK(x) (1LL<<(x))
#define task "tnc"  
typedef long long ll;
const ll INF=1e18;
const int maxn=1e6+5;
const int mod=1e9+7;
const int mo=998244353;
using pi=pair<ll,ll>;
using vi=vector<ll>;
using pii=pair<pair<ll,ll>,ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
int a[10005];
int ok[10005];
/*
int query(int l,int r){
	return 1;
}
int answer(int l,int r){
	return 1;
}
*/
void solve(int N){
	n=N;
	
	int l=1;
	int r=n-1;
	int vt1;
	while(l<=r){
		int mid=(l+r)/2;
		if(query(mid,n)==n-1){
			vt1=mid;
			l=mid+1;
		//	cout<<l<<" "<<r<<"\n";
		}
		else{
			r=mid-1;

			//cout<<l<<" "<<r<<"\n";
		}
	}
	a[vt1]=1;
	ok[1]=1;
	if(vt1>1){
		int d=query(vt1-1,vt1);
		a[vt1-1]=1+d;
		ok[a[vt1-1]]=1;
		for(int i=vt1-2;i>=1;i--){
			int k=query(i,i+1);
			if(a[i+1]+k>=n ||(ok[a[i+1]+k]==1)){
				a[i]=a[i+1]-k;
			}
			else if(a[i+1]-k<=1 || ok[a[i+1]-k]==1){
				a[i]=a[i+1]+k;
			}
			else{
				int k1=query(i,i+2);
				if(a[i+1]>a[i+2]){
					if(k==k1){
                        // be hon a[i+2]
						a[i]=a[i+1]-k;
					}
					else if(a[i+1]-a[i+2]==k1){
						a[i]=a[i+1]-k;
					}
					else {//if(k<k1)
						a[i]=a[i+1]+k;
					}
				}
				else{
					// a[i+1]<a[i+2]
					
					if(a[i+2]-a[i+1]==k1){
						a[i]=a[i+1]+k;
					}
					else if(k1>k){

						a[i]=a[i+1]-k;
					}
					else{// k ==k1
						a[i]=a[i+1]+k;
					}
				}
			}
			ok[a[i]]=1;
		}
	}
	a[vt1+1]=1+query(vt1,vt1+1);
	ok[a[vt1+1]]=1;
	for(int i=vt1+2;i<=n;i++){
		int k=query(i-1,i);
		if(a[i-1]+k>n ||(ok[a[i-1]+k]==1)){
			a[i]=a[i-1]-k;
		}
		else if(a[i-1]-k<=1 || ok[a[i-1]-k]==1){
			a[i]=a[i-1]+k;
		}
		else{
			int k1=query(i-2,i);
			if(a[i-1]>a[i-2]){
				if(k==k1){
					a[i]=a[i-1]-k;
				}
				else if(a[i-1]-a[i-2]==k1){
					a[i]=a[i-1]-k;
				}
				else {//if(k<k1)
					a[i]=a[i-1]+k;
				}
			}
			else{
				if(a[i-2]-a[i-1]==k1){
					a[i]=a[i-1]+k;
				}
				else if(k1>k){
					a[i]=a[i-1]-k;
				}
				else{// k ==k1
					a[i]=a[i-1]+k;
				}
			}
		}
		ok[a[i]]=1;
	}
	for(int i=1;i<=n;i++){
		answer(i,a[i]);
	}

}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:47:6: warning: 'vt1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |  int vt1;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 252 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 3 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 3 ms 308 KB Output is correct
10 Correct 2 ms 312 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 3 ms 208 KB Output is correct
13 Correct 2 ms 220 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 252 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 3 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 3 ms 308 KB Output is correct
10 Correct 2 ms 312 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 3 ms 208 KB Output is correct
13 Correct 2 ms 220 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 11 ms 208 KB Output is correct
19 Correct 10 ms 208 KB Output is correct
20 Correct 8 ms 324 KB Output is correct
21 Correct 13 ms 208 KB Output is correct
22 Correct 5 ms 316 KB Output is correct
23 Correct 10 ms 316 KB Output is correct
24 Correct 11 ms 320 KB Output is correct
25 Correct 9 ms 208 KB Output is correct
26 Correct 11 ms 208 KB Output is correct
27 Correct 13 ms 208 KB Output is correct
28 Correct 13 ms 324 KB Output is correct
29 Correct 12 ms 300 KB Output is correct
30 Correct 12 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 252 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 3 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 3 ms 308 KB Output is correct
10 Correct 2 ms 312 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 3 ms 208 KB Output is correct
13 Correct 2 ms 220 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 11 ms 208 KB Output is correct
19 Correct 10 ms 208 KB Output is correct
20 Correct 8 ms 324 KB Output is correct
21 Correct 13 ms 208 KB Output is correct
22 Correct 5 ms 316 KB Output is correct
23 Correct 10 ms 316 KB Output is correct
24 Correct 11 ms 320 KB Output is correct
25 Correct 9 ms 208 KB Output is correct
26 Correct 11 ms 208 KB Output is correct
27 Correct 13 ms 208 KB Output is correct
28 Correct 13 ms 324 KB Output is correct
29 Correct 12 ms 300 KB Output is correct
30 Correct 12 ms 208 KB Output is correct
31 Correct 20 ms 324 KB Output is correct
32 Correct 36 ms 312 KB Output is correct
33 Correct 58 ms 328 KB Output is correct
34 Correct 59 ms 336 KB Output is correct
35 Correct 46 ms 328 KB Output is correct
36 Correct 40 ms 328 KB Output is correct
37 Correct 41 ms 448 KB Output is correct
38 Correct 44 ms 328 KB Output is correct
39 Correct 48 ms 336 KB Output is correct
40 Correct 65 ms 336 KB Output is correct
41 Correct 52 ms 452 KB Output is correct
42 Correct 51 ms 324 KB Output is correct
43 Correct 37 ms 332 KB Output is correct
44 Correct 49 ms 328 KB Output is correct
45 Correct 62 ms 320 KB Output is correct
46 Correct 56 ms 320 KB Output is correct
47 Correct 61 ms 324 KB Output is correct
48 Correct 28 ms 336 KB Output is correct
49 Correct 68 ms 328 KB Output is correct
50 Correct 60 ms 452 KB Output is correct
51 Correct 47 ms 340 KB Output is correct
52 Correct 60 ms 340 KB Output is correct
53 Correct 51 ms 320 KB Output is correct
54 Correct 71 ms 328 KB Output is correct
55 Correct 26 ms 360 KB Output is correct
56 Correct 56 ms 332 KB Output is correct
57 Correct 53 ms 328 KB Output is correct
58 Correct 53 ms 340 KB Output is correct
59 Correct 57 ms 328 KB Output is correct
60 Correct 67 ms 336 KB Output is correct