답안 #429915

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
429915 2021-06-16T10:27:24 Z hhhhaura 밀림 점프 (APIO21_jumps) C++14
48 / 100
1996 ms 91292 KB
#define wiwihorz
#include "jumps.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define ceil(a, b) ((a + b - 1) / (b))
#define all(x) x.begin(), x.end()

#define MOD 1000000007
#define eps (1e-9)
#define INF 1000000000
using namespace std;

#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L; }
void kout() {cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
int n, lg;
vector<int> L, R, h, t;
vector<vector<int>> l, r, to;
vector<vector<pii>> sp;
int query(int L, int R) {
	if(L > R) return -1;
	int cur = 31 - __builtin_clz(R - L + 1);
	pii ans = max(sp[cur][L], sp[cur][R - (1 << cur) + 1]);
	return ans.second;
}
void init(int N, vector<int> H) {
	n = N, lg = 32 - __builtin_clz(n);
	set<int> s; vector<int> a(n, 0);
	L.assign(n + 2, 0);
	R.assign(n + 2, 0);
	t.assign(n + 2, 0);
	h.assign(n + 2, 0);
	h[0] = h[n + 1] = INF;
	rep(i, 0, n - 1) h[i + 1] = H[i];
	rep(i, 1, n) a[i - 1] = i;
	sort(all(a), [](int x, int y) { return h[x] > h[y]; });
	s.insert(n + 1), s.insert(0);
	for(auto i : a) {
		auto it = s.lower_bound(i);
		int x = *it, y = *prev(it);
		if(h[x] < h[y]) swap(x, y);
		R[i] = x, L[i] = y, t[i] = *it;
		s.insert(i);
	}
	l.assign(lg + 1, vector<int>(n + 2, 0));
	r.assign(lg + 1, vector<int>(n + 2, 0));
	sp.assign(lg + 1, vector<pii>(n + 2, {0, 0}));
	to.assign(lg + 1, vector<int>(n + 2, 0));
	L[0] = R[0] = 0, L[n + 1] = R[n + 1] = n + 1;
	rep(i, 0, n + 1) {
		sp[0][i] = {h[i], i};
		l[0][i] = L[i];
		r[0][i] = R[i];
		to[0][i] = t[i];
	}
	rep(i, 1, lg) rep(j, 0, n + 1) {
		sp[i][j] = max(sp[i - 1][j], sp[i - 1][j + (1 << (i - 1))]);
		l[i][j] = l[i - 1][l[i - 1][j]];
		r[i][j] = r[i - 1][r[i - 1][j]];
		to[i][j] = to[i - 1][to[i - 1][j]];
	}
	return;
}
/*
7 3
3 2 1 6 4 5 7
4 4 6 6
1 3 5 6
0 1 2 2 
*/
int minimum_jumps(int A, int B, int C, int D) {
	A ++ ,B ++ , C ++, D ++;	
	int st, ll = A - 1, rr = B + 1, ans = 0, mx;
	mx = query(C, D);
	while(rr - ll > 1) {
		int mid = (ll + rr) / 2;
		int x = query(mid, B);
		if(h[mx] < h[x]) ll = mid;
		else rr = mid;
	} 
	st = query(rr, B);
	if(st == -1) return -1;
	rrep(i, 0, lg) {
		if(h[r[i][st]] < h[mx] && r[i][st] < C && l[i][st] < C)
			st = r[i][st], ans += (1 << i);
	}
	if(r[0][st] <= D && r[0][st] >= C) return ans + 1;
	rrep(i, 0, lg) if(h[to[i][st]] <= h[C]) {
		if(to[i][st] < C) st = to[i][st], ans += (1 << i);
	}
	st = to[0][st];
	if(st <= D && st >= C) return ans + 1;
	return -1;
}

Compilation message

jumps.cpp:5: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    5 | #pragma loop-opt(on)
      | 
jumps.cpp:23:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   23 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L; }
      |             ^~~~
jumps.cpp:23:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   23 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L; }
      |                     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 323 ms 72564 KB Output is correct
4 Correct 1898 ms 91172 KB Output is correct
5 Correct 1357 ms 44064 KB Output is correct
6 Correct 1996 ms 91292 KB Output is correct
7 Correct 1641 ms 62284 KB Output is correct
8 Correct 1789 ms 91184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Incorrect 1 ms 200 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Incorrect 1 ms 200 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Incorrect 233 ms 73388 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 439 ms 40048 KB Output is correct
5 Correct 1596 ms 91136 KB Output is correct
6 Correct 983 ms 14060 KB Output is correct
7 Correct 1813 ms 91076 KB Output is correct
8 Correct 1054 ms 30212 KB Output is correct
9 Correct 1529 ms 91084 KB Output is correct
10 Correct 1582 ms 91112 KB Output is correct
11 Correct 1469 ms 91124 KB Output is correct
12 Correct 1502 ms 91108 KB Output is correct
13 Correct 1691 ms 91188 KB Output is correct
14 Correct 1314 ms 91132 KB Output is correct
15 Correct 1225 ms 91132 KB Output is correct
16 Correct 1292 ms 91156 KB Output is correct
17 Correct 0 ms 200 KB Output is correct
18 Correct 1 ms 200 KB Output is correct
19 Correct 1 ms 200 KB Output is correct
20 Correct 4 ms 328 KB Output is correct
21 Correct 5 ms 328 KB Output is correct
22 Correct 4 ms 328 KB Output is correct
23 Correct 4 ms 328 KB Output is correct
24 Correct 2 ms 328 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 2 ms 456 KB Output is correct
27 Correct 28 ms 964 KB Output is correct
28 Correct 22 ms 840 KB Output is correct
29 Correct 17 ms 920 KB Output is correct
30 Correct 16 ms 840 KB Output is correct
31 Correct 11 ms 924 KB Output is correct
32 Correct 1 ms 200 KB Output is correct
33 Correct 158 ms 50668 KB Output is correct
34 Correct 308 ms 91156 KB Output is correct
35 Correct 177 ms 91132 KB Output is correct
36 Correct 236 ms 91124 KB Output is correct
37 Correct 209 ms 91156 KB Output is correct
38 Correct 177 ms 91156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 439 ms 40048 KB Output is correct
5 Correct 1596 ms 91136 KB Output is correct
6 Correct 983 ms 14060 KB Output is correct
7 Correct 1813 ms 91076 KB Output is correct
8 Correct 1054 ms 30212 KB Output is correct
9 Correct 1529 ms 91084 KB Output is correct
10 Correct 1582 ms 91112 KB Output is correct
11 Correct 1469 ms 91124 KB Output is correct
12 Correct 1502 ms 91108 KB Output is correct
13 Correct 1691 ms 91188 KB Output is correct
14 Correct 1314 ms 91132 KB Output is correct
15 Correct 1225 ms 91132 KB Output is correct
16 Correct 1292 ms 91156 KB Output is correct
17 Correct 0 ms 200 KB Output is correct
18 Correct 1 ms 200 KB Output is correct
19 Correct 1 ms 200 KB Output is correct
20 Correct 4 ms 328 KB Output is correct
21 Correct 5 ms 328 KB Output is correct
22 Correct 4 ms 328 KB Output is correct
23 Correct 4 ms 328 KB Output is correct
24 Correct 2 ms 328 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 2 ms 456 KB Output is correct
27 Correct 28 ms 964 KB Output is correct
28 Correct 22 ms 840 KB Output is correct
29 Correct 17 ms 920 KB Output is correct
30 Correct 16 ms 840 KB Output is correct
31 Correct 11 ms 924 KB Output is correct
32 Correct 1 ms 200 KB Output is correct
33 Correct 158 ms 50668 KB Output is correct
34 Correct 308 ms 91156 KB Output is correct
35 Correct 177 ms 91132 KB Output is correct
36 Correct 236 ms 91124 KB Output is correct
37 Correct 209 ms 91156 KB Output is correct
38 Correct 177 ms 91156 KB Output is correct
39 Correct 1 ms 200 KB Output is correct
40 Correct 0 ms 200 KB Output is correct
41 Correct 1 ms 200 KB Output is correct
42 Correct 441 ms 40100 KB Output is correct
43 Correct 1237 ms 91156 KB Output is correct
44 Correct 842 ms 14080 KB Output is correct
45 Correct 1617 ms 91188 KB Output is correct
46 Correct 842 ms 30228 KB Output is correct
47 Correct 1530 ms 91088 KB Output is correct
48 Correct 1349 ms 91084 KB Output is correct
49 Correct 1532 ms 91160 KB Output is correct
50 Correct 1390 ms 91188 KB Output is correct
51 Correct 1171 ms 91132 KB Output is correct
52 Correct 1161 ms 91180 KB Output is correct
53 Correct 1184 ms 91096 KB Output is correct
54 Correct 1297 ms 91100 KB Output is correct
55 Correct 1 ms 200 KB Output is correct
56 Correct 427 ms 90796 KB Output is correct
57 Correct 1529 ms 91092 KB Output is correct
58 Correct 711 ms 14900 KB Output is correct
59 Correct 1742 ms 91092 KB Output is correct
60 Correct 743 ms 31180 KB Output is correct
61 Correct 1814 ms 91156 KB Output is correct
62 Correct 1743 ms 91188 KB Output is correct
63 Correct 1606 ms 91148 KB Output is correct
64 Correct 1511 ms 91128 KB Output is correct
65 Correct 1608 ms 91140 KB Output is correct
66 Correct 1821 ms 91184 KB Output is correct
67 Correct 1560 ms 91112 KB Output is correct
68 Correct 1658 ms 91156 KB Output is correct
69 Correct 1 ms 200 KB Output is correct
70 Correct 1 ms 200 KB Output is correct
71 Correct 3 ms 328 KB Output is correct
72 Correct 4 ms 328 KB Output is correct
73 Correct 3 ms 328 KB Output is correct
74 Correct 4 ms 328 KB Output is correct
75 Correct 4 ms 328 KB Output is correct
76 Correct 0 ms 200 KB Output is correct
77 Correct 1 ms 200 KB Output is correct
78 Correct 2 ms 200 KB Output is correct
79 Correct 2 ms 328 KB Output is correct
80 Correct 3 ms 328 KB Output is correct
81 Correct 3 ms 284 KB Output is correct
82 Correct 4 ms 328 KB Output is correct
83 Correct 5 ms 328 KB Output is correct
84 Correct 1 ms 328 KB Output is correct
85 Correct 4 ms 328 KB Output is correct
86 Correct 21 ms 840 KB Output is correct
87 Correct 32 ms 840 KB Output is correct
88 Correct 21 ms 840 KB Output is correct
89 Correct 19 ms 840 KB Output is correct
90 Correct 19 ms 900 KB Output is correct
91 Correct 1 ms 328 KB Output is correct
92 Correct 2 ms 456 KB Output is correct
93 Correct 27 ms 912 KB Output is correct
94 Correct 24 ms 840 KB Output is correct
95 Correct 24 ms 912 KB Output is correct
96 Correct 22 ms 820 KB Output is correct
97 Correct 30 ms 904 KB Output is correct
98 Correct 1 ms 200 KB Output is correct
99 Correct 292 ms 90900 KB Output is correct
100 Correct 324 ms 91156 KB Output is correct
101 Correct 172 ms 91236 KB Output is correct
102 Correct 250 ms 91156 KB Output is correct
103 Correct 254 ms 91080 KB Output is correct
104 Correct 177 ms 91156 KB Output is correct
105 Correct 1 ms 200 KB Output is correct
106 Correct 138 ms 50716 KB Output is correct
107 Correct 353 ms 91132 KB Output is correct
108 Correct 173 ms 91252 KB Output is correct
109 Correct 244 ms 91120 KB Output is correct
110 Correct 218 ms 91124 KB Output is correct
111 Correct 178 ms 91128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 323 ms 72564 KB Output is correct
4 Correct 1898 ms 91172 KB Output is correct
5 Correct 1357 ms 44064 KB Output is correct
6 Correct 1996 ms 91292 KB Output is correct
7 Correct 1641 ms 62284 KB Output is correct
8 Correct 1789 ms 91184 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 200 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
13 Incorrect 1 ms 200 KB Output isn't correct
14 Halted 0 ms 0 KB -