답안 #981343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
981343 2024-05-13T05:15:09 Z Amaarsaa Xylophone (JOI18_xylophone) C++14
47 / 100
46 ms 1008 KB
#include<bits/stdc++.h>
#include "xylophone.h"

using namespace std;

int a[5002], ans[5002];

void solve(int N) {
	int ind, mid,i, s,x1, x2, p, n = N, lo, hi;
	
	lo = 1;
	hi = n;
	int r, b[5005], c[5005], ens[5005];
	while (lo < hi) {
		mid = (lo + hi)/2;
		if ( query(1, mid) == n - 1) hi = mid;
		else lo = mid + 1;
	}
	ind = lo;
	ans[1] = 0;
	ans[2] = 0 + query(1, 2);
	r = ans[2];
	int mx = ans[2];
	for ( i = 3; i <= n; i ++) {
		s = query(i - 1, i);
		p = query(i - 2, i);
		b[i]= s;
		c[i] = p;
		x1 = ans[i - 1] - s;
		x2 = ans[i - 1] + s;
		if ( max(x1, max(ans[i - 1], ans[i - 2])) - min(x1, min(ans[i - 1], ans[i - 2])) == p) {
			ans[i] = x1;
		} 
		if ( max(x2, max(ans[i - 1], ans[i - 2])) - min(x2, min(ans[i - 1], ans[i - 2])) == p) {
			ans[i] = x2;
		} 
		mx = max(mx,ans[i]);
	}
	int j = 1;
	for (i = 1; i <= n; i ++) {
		ens[i] = ans[i]= ans[i] + (n - mx);
		if ( ans[i] == n) j = i;
	}
	sort ( ens + 1, ens + n + 1);
	int can = 1;
	for (i =1; i <= n; i ++) if ( ens[i] != i) can = 0;
	if (  can && ind == j) {
//		for (i = 1; i <= n; i ++) cout << ans[i] << " ";
		for (i = 1; i <= n; i ++) answer(i, ans[i]);
		return ;
	}
	ans[1] = 0;
	ans[2] = -r;
	mx = 0;
	for ( i = 3; i <= n; i ++) {
		s = b[i];
		p = c[i];
		x1 = ans[i - 1] - s;
		x2 = ans[i - 1] + s;
		if ( max(x1, max(ans[i - 1], ans[i - 2])) - min(x1, min(ans[i - 1], ans[i - 2])) == p) {
			ans[i] = x1;
		} 
		if ( max(x2, max(ans[i - 1], ans[i - 2])) - min(x2, min(ans[i - 1], ans[i - 2])) == p) {
			ans[i] = x2;
		} 
		mx = max(mx,ans[i]);
	}
	for (i = 1; i <= n; i ++) ans[i] = ans[i] + (n - mx);
//	for (i = 1; i <= n; i ++) cout << ans[i] << " ";
	for (i =1 ; i<= n; i++) answer(i, ans[i]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 4 ms 496 KB Output is correct
18 Correct 7 ms 496 KB Output is correct
19 Correct 9 ms 752 KB Output is correct
20 Correct 9 ms 492 KB Output is correct
21 Correct 11 ms 744 KB Output is correct
22 Correct 9 ms 748 KB Output is correct
23 Correct 8 ms 496 KB Output is correct
24 Correct 9 ms 500 KB Output is correct
25 Correct 10 ms 500 KB Output is correct
26 Correct 8 ms 504 KB Output is correct
27 Correct 10 ms 500 KB Output is correct
28 Correct 8 ms 496 KB Output is correct
29 Correct 9 ms 1008 KB Output is correct
30 Correct 12 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 4 ms 496 KB Output is correct
18 Correct 7 ms 496 KB Output is correct
19 Correct 9 ms 752 KB Output is correct
20 Correct 9 ms 492 KB Output is correct
21 Correct 11 ms 744 KB Output is correct
22 Correct 9 ms 748 KB Output is correct
23 Correct 8 ms 496 KB Output is correct
24 Correct 9 ms 500 KB Output is correct
25 Correct 10 ms 500 KB Output is correct
26 Correct 8 ms 504 KB Output is correct
27 Correct 10 ms 500 KB Output is correct
28 Correct 8 ms 496 KB Output is correct
29 Correct 9 ms 1008 KB Output is correct
30 Correct 12 ms 492 KB Output is correct
31 Correct 24 ms 736 KB Output is correct
32 Correct 26 ms 748 KB Output is correct
33 Correct 41 ms 752 KB Output is correct
34 Incorrect 46 ms 732 KB Wrong Answer [2]
35 Halted 0 ms 0 KB -