답안 #306783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
306783 2020-09-26T09:26:29 Z syy Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
269 ms 23928 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

const int sqr = 175;
int n, m, b[30005], p[30005], dist[30005][175];
vi big[30005], small[30005];
deque<pii> dq; //building, cur jump, dist

int main() {
	fastio; cin >> n >> m;
	FOR(i, 0, m-1) {
		cin >> b[i] >> p[i];
		if (p[i] > sqr) big[b[i]].pb(p[i]);
		else small[b[i]].pb(p[i]);
	}
	memset(dist, -1, sizeof dist);
	dist[b[0]][0] = 0; dq.push_back(pii(0, pi(b[0], 0)));
	while (!dq.empty()) {
		pii cur = dq.front(); dq.pop_front();
		int x = cur.s.f, d = cur.f, jump = cur.s.s;
		if (jump == 0) { //transferring
			if (d != dist[x][0]) continue;
			for (auto it:big[x]) {
				if (x + it < n) dq.push_back(pii(d+1, pi(x+it, it)));
				if (x - it >= 0) dq.push_back(pii(d+1, pi(x-it, -it)));
			}
			for (auto it:small[x]) {
				if (dist[x][it] == -1 or dist[x][it] > d) {
					dist[x][it] = d;
					dq.push_front(pii(d, pi(x, it)));
				}
			}
		} else if (jump > 0 and jump < sqr) { //small dog
			if (d != dist[x][jump]) continue;
			if (dist[x][0] == -1 or dist[x][0] > d) {
				dist[x][0] = d;
				dq.push_front(pii(d, pi(x, 0)));
			}
			for (auto it:{x - jump, x + jump}) if (it >= 0 and it < n) {
				if (dist[it][jump] == -1 or dist[it][jump] > d + 1) {
					dist[it][jump] = d + 1;
					dq.push_back(pii(d+1, pi(it, jump)));
				}
			}
		} else { //big dog
			//get off
			if (dist[x][0] == -1 or dist[x][0] > d) {
				dist[x][0] = d;
				dq.push_front(pii(d, pi(x, 0)));
			}
			//continue
			if (x + jump < n and x + jump >= 0) dq.push_back(pii(d+1, pi(x+jump, jump)));
		}
	}
	cout << dist[b[1]][0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 22272 KB Output is correct
2 Correct 14 ms 22272 KB Output is correct
3 Correct 14 ms 22272 KB Output is correct
4 Correct 14 ms 22272 KB Output is correct
5 Correct 14 ms 22272 KB Output is correct
6 Correct 14 ms 22272 KB Output is correct
7 Correct 13 ms 22272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 22272 KB Output is correct
2 Correct 14 ms 22272 KB Output is correct
3 Correct 14 ms 22272 KB Output is correct
4 Correct 14 ms 22272 KB Output is correct
5 Correct 14 ms 22272 KB Output is correct
6 Correct 14 ms 22272 KB Output is correct
7 Correct 13 ms 22272 KB Output is correct
8 Correct 14 ms 22272 KB Output is correct
9 Correct 14 ms 22272 KB Output is correct
10 Correct 14 ms 22272 KB Output is correct
11 Correct 15 ms 22400 KB Output is correct
12 Correct 16 ms 22400 KB Output is correct
13 Correct 14 ms 22400 KB Output is correct
14 Correct 14 ms 22400 KB Output is correct
15 Correct 15 ms 22400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 22272 KB Output is correct
2 Correct 14 ms 22272 KB Output is correct
3 Correct 13 ms 22272 KB Output is correct
4 Correct 14 ms 22272 KB Output is correct
5 Correct 14 ms 22272 KB Output is correct
6 Correct 13 ms 22272 KB Output is correct
7 Correct 13 ms 22272 KB Output is correct
8 Correct 14 ms 22272 KB Output is correct
9 Correct 14 ms 22400 KB Output is correct
10 Correct 15 ms 22272 KB Output is correct
11 Correct 15 ms 22400 KB Output is correct
12 Correct 15 ms 22296 KB Output is correct
13 Correct 14 ms 22400 KB Output is correct
14 Correct 14 ms 22400 KB Output is correct
15 Correct 14 ms 22400 KB Output is correct
16 Correct 14 ms 22272 KB Output is correct
17 Correct 15 ms 22400 KB Output is correct
18 Correct 14 ms 22300 KB Output is correct
19 Correct 17 ms 22400 KB Output is correct
20 Correct 14 ms 22400 KB Output is correct
21 Correct 15 ms 22400 KB Output is correct
22 Correct 14 ms 22400 KB Output is correct
23 Correct 14 ms 22400 KB Output is correct
24 Correct 15 ms 22400 KB Output is correct
25 Correct 14 ms 22400 KB Output is correct
26 Correct 14 ms 22400 KB Output is correct
27 Correct 14 ms 22400 KB Output is correct
28 Correct 16 ms 22400 KB Output is correct
29 Correct 16 ms 22400 KB Output is correct
30 Correct 15 ms 22272 KB Output is correct
31 Correct 16 ms 22272 KB Output is correct
32 Correct 16 ms 22272 KB Output is correct
33 Correct 18 ms 22400 KB Output is correct
34 Correct 17 ms 22400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 22272 KB Output is correct
2 Correct 14 ms 22272 KB Output is correct
3 Correct 14 ms 22272 KB Output is correct
4 Correct 13 ms 22272 KB Output is correct
5 Correct 14 ms 22272 KB Output is correct
6 Correct 14 ms 22272 KB Output is correct
7 Correct 14 ms 22272 KB Output is correct
8 Correct 14 ms 22304 KB Output is correct
9 Correct 14 ms 22272 KB Output is correct
10 Correct 13 ms 22272 KB Output is correct
11 Correct 15 ms 22400 KB Output is correct
12 Correct 14 ms 22400 KB Output is correct
13 Correct 14 ms 22400 KB Output is correct
14 Correct 14 ms 22400 KB Output is correct
15 Correct 14 ms 22400 KB Output is correct
16 Correct 14 ms 22272 KB Output is correct
17 Correct 15 ms 22400 KB Output is correct
18 Correct 14 ms 22400 KB Output is correct
19 Correct 14 ms 22400 KB Output is correct
20 Correct 15 ms 22400 KB Output is correct
21 Correct 14 ms 22400 KB Output is correct
22 Correct 14 ms 22400 KB Output is correct
23 Correct 14 ms 22400 KB Output is correct
24 Correct 15 ms 22400 KB Output is correct
25 Correct 17 ms 22400 KB Output is correct
26 Correct 16 ms 22400 KB Output is correct
27 Correct 15 ms 22400 KB Output is correct
28 Correct 16 ms 22400 KB Output is correct
29 Correct 15 ms 22272 KB Output is correct
30 Correct 16 ms 22272 KB Output is correct
31 Correct 15 ms 22272 KB Output is correct
32 Correct 15 ms 22272 KB Output is correct
33 Correct 19 ms 22400 KB Output is correct
34 Correct 17 ms 22400 KB Output is correct
35 Correct 23 ms 23168 KB Output is correct
36 Correct 16 ms 22400 KB Output is correct
37 Correct 24 ms 23168 KB Output is correct
38 Correct 26 ms 23416 KB Output is correct
39 Correct 27 ms 23416 KB Output is correct
40 Correct 25 ms 23424 KB Output is correct
41 Correct 25 ms 23416 KB Output is correct
42 Correct 21 ms 23040 KB Output is correct
43 Correct 19 ms 23040 KB Output is correct
44 Correct 20 ms 23040 KB Output is correct
45 Correct 27 ms 23260 KB Output is correct
46 Correct 26 ms 23168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 22272 KB Output is correct
2 Correct 14 ms 22272 KB Output is correct
3 Correct 14 ms 22272 KB Output is correct
4 Correct 14 ms 22272 KB Output is correct
5 Correct 14 ms 22272 KB Output is correct
6 Correct 14 ms 22272 KB Output is correct
7 Correct 14 ms 22272 KB Output is correct
8 Correct 13 ms 22272 KB Output is correct
9 Correct 13 ms 22272 KB Output is correct
10 Correct 14 ms 22272 KB Output is correct
11 Correct 15 ms 22400 KB Output is correct
12 Correct 14 ms 22304 KB Output is correct
13 Correct 14 ms 22400 KB Output is correct
14 Correct 14 ms 22400 KB Output is correct
15 Correct 14 ms 22400 KB Output is correct
16 Correct 14 ms 22300 KB Output is correct
17 Correct 15 ms 22400 KB Output is correct
18 Correct 14 ms 22528 KB Output is correct
19 Correct 14 ms 22272 KB Output is correct
20 Correct 14 ms 22400 KB Output is correct
21 Correct 14 ms 22340 KB Output is correct
22 Correct 14 ms 22400 KB Output is correct
23 Correct 15 ms 22400 KB Output is correct
24 Correct 15 ms 22400 KB Output is correct
25 Correct 14 ms 22400 KB Output is correct
26 Correct 15 ms 22528 KB Output is correct
27 Correct 15 ms 22400 KB Output is correct
28 Correct 16 ms 22400 KB Output is correct
29 Correct 16 ms 22272 KB Output is correct
30 Correct 15 ms 22272 KB Output is correct
31 Correct 15 ms 22272 KB Output is correct
32 Correct 15 ms 22272 KB Output is correct
33 Correct 18 ms 22400 KB Output is correct
34 Correct 17 ms 22400 KB Output is correct
35 Correct 23 ms 23168 KB Output is correct
36 Correct 16 ms 22400 KB Output is correct
37 Correct 24 ms 23168 KB Output is correct
38 Correct 25 ms 23416 KB Output is correct
39 Correct 26 ms 23424 KB Output is correct
40 Correct 26 ms 23424 KB Output is correct
41 Correct 25 ms 23424 KB Output is correct
42 Correct 19 ms 23040 KB Output is correct
43 Correct 18 ms 23040 KB Output is correct
44 Correct 19 ms 23040 KB Output is correct
45 Correct 27 ms 23168 KB Output is correct
46 Correct 26 ms 23168 KB Output is correct
47 Correct 58 ms 23552 KB Output is correct
48 Correct 21 ms 23168 KB Output is correct
49 Correct 20 ms 23168 KB Output is correct
50 Correct 18 ms 22912 KB Output is correct
51 Correct 44 ms 23552 KB Output is correct
52 Correct 49 ms 23552 KB Output is correct
53 Correct 29 ms 23424 KB Output is correct
54 Correct 15 ms 22272 KB Output is correct
55 Correct 16 ms 22272 KB Output is correct
56 Correct 24 ms 23680 KB Output is correct
57 Correct 42 ms 22400 KB Output is correct
58 Correct 23 ms 22912 KB Output is correct
59 Correct 28 ms 23160 KB Output is correct
60 Correct 30 ms 23164 KB Output is correct
61 Correct 27 ms 23040 KB Output is correct
62 Correct 76 ms 23928 KB Output is correct
63 Correct 92 ms 23168 KB Output is correct
64 Correct 105 ms 23168 KB Output is correct
65 Correct 145 ms 23160 KB Output is correct
66 Correct 269 ms 23168 KB Output is correct
67 Correct 266 ms 23160 KB Output is correct