답안 #930084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930084 2024-02-18T12:51:08 Z ByeWorld Xylophone (JOI18_xylophone) C++14
0 / 100
0 ms 436 KB
#include "xylophone.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
//#define int long long
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> ipii;
const int INF = 1e9+10;
const int MAXN = 2e3+10;
int A[5010], tag[5010];

int n;

void solve(int N) {
	n = N;
	int val = n-1, l = 1, r = n, las = 1;
	while(l <= r){
		int te = query(md, n);
		if(te==n-1){
			las = md; l = md+1; 
		} else r = md-1;	
	}
	// las -> 1
	A[las] = 1;

	for(int i=las-1; i>=1; i--){ // ke kiri
		if(i==las-1){
			int te = query(las-1, las);
			A[las-1] = te+1;
			tag[A[i]] = 1;
			continue;
		}

		// ngerjain A[i]
		int dif = query(i, i+1); // consider A[i+1]-dif / A[i]+dif
		if(tag[A[i+1]-dif]){
			A[i] = A[i+1]+dif; 
			tag[A[i]] = 1;
			continue;
		} 
		if(tag[A[i+1]+dif]){
			A[i] = A[i+1]-dif; 
			tag[A[i]] = 1;
			continue;
		} 

		if(A[i+1] < A[i+2]){ // lebih tinggi, cek yg -dif
			int cek = A[i+2] - (A[i+1]-dif);
			if(query(i, i+2) == cek) A[i] = A[i+1]-dif;
			else A[i] = A[i+1]+dif;
		} else { // lebih rendah
			int cek = (A[i+1]+dif) - A[i+2];
			if(query(i, i+2) == cek) A[i] = A[i+1]+dif;
			else A[i] = A[i+1]-dif;
		}
		tag[A[i]] = 1;
	}
	for(int i=las+1; i<=n; i++){
		if(i==las+1){
			int te = query(las, las+1);
			A[las+1] = te+1;
			tag[A[i]] = 1;
			continue;
		}

		// ngerjain A[i]
		int dif = query(i-1, i); // consider A[i-1]-dif / A[i-1]+dif
		if(tag[A[i-1]-dif]){
			A[i] = A[i-1]+dif; 
			tag[A[i]] = 1;
			continue;
		}
		if(tag[A[i-1]+dif]){
			A[i] = A[i-1]-dif; 
			tag[A[i]] = 1;
			continue;
		}

		if(A[i-2] < A[i-1]){ // lebih tinggi, cek yg +dif
			int cek = (A[i-1]+dif) - A[i-2];
			if(query(i-2, i) == cek) A[i] = A[i-1]+dif;
			else A[i] = A[i-1]-dif;
		} else { // lebih rendah
			int cek = A[i-2] - (A[i-1]-dif);
			if(query(i-2, i) == cek) A[i] = A[i-1]-dif;
			else A[i] = A[i-1]+dif;
		}
		tag[A[i]] = 1;
	}

	for(int i = 1; i <= n; i++) cout << A[i] << " \n"[i==n];
	for(int i = 1; i <= n; i++) {
		answer(i, A[i]);
	}
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:21:6: warning: unused variable 'val' [-Wunused-variable]
   21 |  int val = n-1, l = 1, r = n, las = 1;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 436 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 436 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 436 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -