답안 #931690

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931690 2024-02-22T09:26:46 Z thunopro Xylophone (JOI18_xylophone) C++14
0 / 100
1 ms 448 KB
#include<bits/stdc++.h>
#include "xylophone.h"
using namespace std ; 
#define maxn 200009
#define ll long long 
#define pb push_back 
#define fi first 
#define se second 
#define left id<<1
#define right id<<1|1 
#define re exit(0); 
#define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()+1
const int mod = 1e9+7 ;
const int INF = 1e9 ; 

typedef vector<int> vi ; 
typedef pair<int,int> pii ; 
typedef vector<pii> vii ; 

template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; } 
template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; } 

void add ( int &a , int b ) 
{
	a += b ; 
	if ( a >= mod ) a -= mod ; 
	if ( a < 0 ) a += mod ; 
}

void rf () 
{
	freopen ("bai1.inp","r",stdin) ;
}

int _pow ( int a , int n ) 
{
	if ( n == 0 ) return 1 ; 
	int res = _pow (a,n/2) ; 
	if ( n % 2 ) return 1ll*res*res%mod*a%mod ; 
	else return 1ll*res*res%mod ; 
}

int n ; 
int a [maxn] ; 
bool used [maxn] ; 
//int query ( int l , int r ) 
//{
//	cout << l << " " << r << endl ; 
//	int x ; cin >> x ; 
//	return x ; 
//}

void assign ( int &x , int y ) 
{
	x = y ; 
	used [y] = true ; 
}
bool ban ( int x ) 
{
	return ( x <= 0 || x > n || used [x] ) ; 
}
void solve ( int N ) 
{
	n = N ; 
	int pos1 ; 
	int l = 1 , r = n-1 ; 
	while ( l <= r ) 
	{
		int mid = (l+r)/2 ; 
		if ( query (mid,n) == n-1 ) pos1 = mid , l = mid + 1 ; 
		else r = mid - 1 ; 
	}
	a [pos1] = 1 , used [1] = true ; 
	if ( pos1 > 1 ) 
	{
		assign (a[pos1-1],1+query(pos1-1,pos1)) ; 
		for ( int i = pos1-2 ; i >= 1 ; i -- ) 
		{
			int diff1 = query (i,i+1) ; 
			if ( ban (a[i+1]-diff1) ) assign (a[i],a[i+1]+diff1) ; 
			else if ( ban (a[i+1]+diff1) ) assign (a[i],a[i+1]-diff1) ; 
			else 
			{
				int diff2 = query (i,i+2) ; 
				if ( diff1 == diff2 ) 
				{
					if ( a [i+1] < a [i+2] ) assign (a[i],a[i+1]+diff1) ; 
					else assign (a[i],a[i+1]-diff1) ; 
				}
				else 
				{
					if ( a [i+1] < a [i+2] && a [i+2]-a[i+1] != diff2 ) assign (a[i],a[i+1]-diff1) ; 
					else assign (a[i],a[i+1]+diff1) ; 
				}
			}
		}
	}
	if ( pos1 < n ) 
	{
		assign (a[pos1+1],1+query(pos1,pos1+1)) ; 
		for ( int i = pos1+2 ; i <= n ; i ++ ) 
		{
			int diff1 = query (i-1,i) ; 
			if ( ban (a[i-1]-diff1) ) assign (a[i],a[i-1]+diff1) ;
			else if ( ban (a[i-1]+diff1) ) assign (a[i],a[i-1]-diff1) ; 
			else 
			{
				int diff2 = query (i-2,i) ; 
				if ( diff1 == diff2 )
				{
					if ( a [i-2] > a [i-1] ) assign (a[i],a[i-1]+diff1) ; 
					else assign (a[i],a[i-1]-diff1) ; 
				}
				else 
				{
					if ( a [i-2] > a [i-1] && a[i-2]-a[i-1] != diff2 ) assign (a[i],a[i-1]-diff1) ; 
					else assign (a[i],a[i-1]+diff1) ; 
				}
			}
		}
	}
//	for ( int i = 1 ; i <= n ; i ++ ) cout << a [i] << " " ; re
	for ( int i = 1 ; i <= n ; i ++ ) answer (i,a[i]) ; 
}
//int main () 
//{
//	ios_base::sync_with_stdio(0); 
//	cin.tie(0);cout.tie(0); 
////	rf () ; 
//	solve (5) ; 
//}

Compilation message

xylophone.cpp: In function 'void rf()':
xylophone.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:65:6: warning: 'pos1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   65 |  int pos1 ;
      |      ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 444 KB Output is correct
2 Correct 0 ms 448 KB Output is correct
3 Incorrect 1 ms 436 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 444 KB Output is correct
2 Correct 0 ms 448 KB Output is correct
3 Incorrect 1 ms 436 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 444 KB Output is correct
2 Correct 0 ms 448 KB Output is correct
3 Incorrect 1 ms 436 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -