답안 #547521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547521 2022-04-10T21:58:06 Z farhan132 Xylophone (JOI18_xylophone) C++17
100 / 100
97 ms 444 KB
#include "xylophone.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef int ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<ll> vll;
typedef pair<ll , ll> ii;
typedef vector< ii > vii;
typedef pair < pair < ll , ll > , pair < ll , ll > > cm; 
typedef tuple < ll,  ll, ll > tp;
 
#define ff first
#define ss second
#define pb push_back
#define in insert

const ll N = 5005;

ll a[N] , slope[N] , pre[N];

ll sign(ll x){
	if(x < 0) return -1;
	return 1;
}


void solve(int n) {
	pre[1] = 0;
	slope[2] = pre[2] = query(1, 2);
	for(ll i = 3; i <= n; i++){
		ll k1 = query(i-1,i);
		ll k2 = query(i-2,i);
		if(abs(k1) + abs(slope[i - 1]) == abs(k2)) slope[i] = sign(slope[i-1]) * k1;
		else slope[i] = sign(-slope[i-1]) * k1;
		pre[i] = pre[i - 1] + slope[i];
	}
	ii mn = {1e9, 0} , mx = {-1e9, 0};
	for(ll i = 1; i <= n; i++){
		mn = min(mn, {pre[i], i});
		mx = max(mx, {pre[i], i});
	}
	ll s = 1, cur;
	if(mn.ss < mx.ss){
		cur = 1 + abs(mn.ff);
	}else{
		s = -1;
		//cout << mx.ff << '\n';
		cur = 1 +  mx.ff;
	}
	for(ll i = 1; i <= n; i++){
		pre[i] *= s;
		answer(i, cur + pre[i]);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 2 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 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 3 ms 304 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 2 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 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 3 ms 304 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 16 ms 308 KB Output is correct
19 Correct 16 ms 288 KB Output is correct
20 Correct 13 ms 300 KB Output is correct
21 Correct 17 ms 208 KB Output is correct
22 Correct 15 ms 208 KB Output is correct
23 Correct 16 ms 288 KB Output is correct
24 Correct 17 ms 308 KB Output is correct
25 Correct 14 ms 208 KB Output is correct
26 Correct 12 ms 208 KB Output is correct
27 Correct 16 ms 300 KB Output is correct
28 Correct 16 ms 208 KB Output is correct
29 Correct 9 ms 296 KB Output is correct
30 Correct 15 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 2 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 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 3 ms 304 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 16 ms 308 KB Output is correct
19 Correct 16 ms 288 KB Output is correct
20 Correct 13 ms 300 KB Output is correct
21 Correct 17 ms 208 KB Output is correct
22 Correct 15 ms 208 KB Output is correct
23 Correct 16 ms 288 KB Output is correct
24 Correct 17 ms 308 KB Output is correct
25 Correct 14 ms 208 KB Output is correct
26 Correct 12 ms 208 KB Output is correct
27 Correct 16 ms 300 KB Output is correct
28 Correct 16 ms 208 KB Output is correct
29 Correct 9 ms 296 KB Output is correct
30 Correct 15 ms 208 KB Output is correct
31 Correct 33 ms 308 KB Output is correct
32 Correct 46 ms 428 KB Output is correct
33 Correct 68 ms 440 KB Output is correct
34 Correct 75 ms 312 KB Output is correct
35 Correct 68 ms 428 KB Output is correct
36 Correct 64 ms 328 KB Output is correct
37 Correct 72 ms 436 KB Output is correct
38 Correct 60 ms 444 KB Output is correct
39 Correct 79 ms 300 KB Output is correct
40 Correct 76 ms 320 KB Output is correct
41 Correct 75 ms 420 KB Output is correct
42 Correct 85 ms 316 KB Output is correct
43 Correct 78 ms 436 KB Output is correct
44 Correct 78 ms 420 KB Output is correct
45 Correct 73 ms 328 KB Output is correct
46 Correct 43 ms 312 KB Output is correct
47 Correct 79 ms 424 KB Output is correct
48 Correct 73 ms 320 KB Output is correct
49 Correct 68 ms 320 KB Output is correct
50 Correct 65 ms 304 KB Output is correct
51 Correct 60 ms 312 KB Output is correct
52 Correct 79 ms 328 KB Output is correct
53 Correct 75 ms 300 KB Output is correct
54 Correct 82 ms 324 KB Output is correct
55 Correct 77 ms 296 KB Output is correct
56 Correct 93 ms 348 KB Output is correct
57 Correct 81 ms 412 KB Output is correct
58 Correct 70 ms 324 KB Output is correct
59 Correct 83 ms 304 KB Output is correct
60 Correct 97 ms 308 KB Output is correct