답안 #930085

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930085 2024-02-18T12:52:12 Z ByeWorld Xylophone (JOI18_xylophone) C++14
100 / 100
48 ms 1704 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 Correct 1 ms 444 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 440 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 440 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 448 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 1 ms 440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 444 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 440 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 440 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 448 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 1 ms 440 KB Output is correct
16 Correct 2 ms 444 KB Output is correct
17 Correct 3 ms 692 KB Output is correct
18 Correct 7 ms 692 KB Output is correct
19 Correct 8 ms 692 KB Output is correct
20 Correct 5 ms 948 KB Output is correct
21 Correct 7 ms 444 KB Output is correct
22 Correct 6 ms 696 KB Output is correct
23 Correct 4 ms 956 KB Output is correct
24 Correct 10 ms 700 KB Output is correct
25 Correct 7 ms 696 KB Output is correct
26 Correct 8 ms 448 KB Output is correct
27 Correct 6 ms 452 KB Output is correct
28 Correct 8 ms 692 KB Output is correct
29 Correct 8 ms 696 KB Output is correct
30 Correct 8 ms 696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 444 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 440 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 440 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 448 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 1 ms 440 KB Output is correct
16 Correct 2 ms 444 KB Output is correct
17 Correct 3 ms 692 KB Output is correct
18 Correct 7 ms 692 KB Output is correct
19 Correct 8 ms 692 KB Output is correct
20 Correct 5 ms 948 KB Output is correct
21 Correct 7 ms 444 KB Output is correct
22 Correct 6 ms 696 KB Output is correct
23 Correct 4 ms 956 KB Output is correct
24 Correct 10 ms 700 KB Output is correct
25 Correct 7 ms 696 KB Output is correct
26 Correct 8 ms 448 KB Output is correct
27 Correct 6 ms 452 KB Output is correct
28 Correct 8 ms 692 KB Output is correct
29 Correct 8 ms 696 KB Output is correct
30 Correct 8 ms 696 KB Output is correct
31 Correct 16 ms 452 KB Output is correct
32 Correct 23 ms 944 KB Output is correct
33 Correct 30 ms 952 KB Output is correct
34 Correct 26 ms 1204 KB Output is correct
35 Correct 30 ms 708 KB Output is correct
36 Correct 25 ms 940 KB Output is correct
37 Correct 39 ms 964 KB Output is correct
38 Correct 34 ms 940 KB Output is correct
39 Correct 32 ms 704 KB Output is correct
40 Correct 36 ms 700 KB Output is correct
41 Correct 41 ms 936 KB Output is correct
42 Correct 24 ms 956 KB Output is correct
43 Correct 34 ms 696 KB Output is correct
44 Correct 30 ms 1704 KB Output is correct
45 Correct 40 ms 712 KB Output is correct
46 Correct 29 ms 1204 KB Output is correct
47 Correct 30 ms 696 KB Output is correct
48 Correct 39 ms 708 KB Output is correct
49 Correct 32 ms 468 KB Output is correct
50 Correct 34 ms 468 KB Output is correct
51 Correct 34 ms 700 KB Output is correct
52 Correct 34 ms 936 KB Output is correct
53 Correct 35 ms 720 KB Output is correct
54 Correct 39 ms 708 KB Output is correct
55 Correct 48 ms 456 KB Output is correct
56 Correct 40 ms 944 KB Output is correct
57 Correct 30 ms 468 KB Output is correct
58 Correct 36 ms 952 KB Output is correct
59 Correct 35 ms 460 KB Output is correct
60 Correct 39 ms 696 KB Output is correct