답안 #41498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41498 2018-02-17T11:55:14 Z RockyB Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
447 ms 64084 KB
/// In The Name Of God
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
 
#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
 
#define nl '\n'
#define ioi exit(0);
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
const int N = (int)3e4 + 7;
const int K = 175;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;
 
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
 
using namespace std;
 
int n, m;
int sta, fn;
int b[N], p[N];
vector < pair <int, int> > g[N];
set <int> a[N];

ll d[N];

int main() {
	#ifdef IOI2018
		freopen ("in.txt", "r", stdin);
	#endif
	Kazakhstan
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		cin >> b[i] >> p[i];
		if (i == 1) sta = b[i];
		if (i == 2) fn = b[i];
		a[b[i]].insert(p[i]);
	}
	for (int i = 0; i < n; i++) {
		for (auto it : a[i]) {
			int p = i + it, cnt = 0;
			while (p < n) {
				g[i].pb({p, ++cnt});
				if (a[p].count(it)) break;
				p += it;
			}
			p = i - it, cnt = 0;
			while (p >= 0) {
				g[i].pb({p, ++cnt});
				if (a[p].count(it)) break;
				p -= it;
			}
		}
	}
	set < pair <ll, int > > st;
	memset(d, 0x3f, sizeof(d));
	st.insert({0, sta});
	d[sta] = 0;
	while (sz(st)) {
		pair <ll, int> v = *st.begin();
		st.erase(st.begin());
		for (auto to : g[v.s]) {
			if (d[to.f] > v.f + to.s) {
				st.erase({d[to.f], to.f});
				d[to.f] = v.f + to.s;
				st.insert({d[to.f], to.f});
			}
		}
	}
	if (d[fn] >= linf) cout << -1;
	else cout << d[fn];
	ioi
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2784 KB Output is correct
3 Correct 3 ms 2784 KB Output is correct
4 Correct 4 ms 2784 KB Output is correct
5 Correct 3 ms 2924 KB Output is correct
6 Correct 4 ms 2924 KB Output is correct
7 Correct 4 ms 2924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2924 KB Output is correct
2 Correct 3 ms 2924 KB Output is correct
3 Correct 4 ms 2924 KB Output is correct
4 Correct 3 ms 2924 KB Output is correct
5 Correct 3 ms 2924 KB Output is correct
6 Correct 3 ms 2924 KB Output is correct
7 Correct 3 ms 2924 KB Output is correct
8 Correct 4 ms 2924 KB Output is correct
9 Correct 4 ms 2924 KB Output is correct
10 Correct 4 ms 2924 KB Output is correct
11 Correct 4 ms 3052 KB Output is correct
12 Correct 4 ms 3052 KB Output is correct
13 Correct 4 ms 3052 KB Output is correct
14 Correct 4 ms 3052 KB Output is correct
15 Correct 4 ms 3052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3052 KB Output is correct
2 Correct 3 ms 3052 KB Output is correct
3 Correct 3 ms 3052 KB Output is correct
4 Correct 3 ms 3052 KB Output is correct
5 Correct 4 ms 3052 KB Output is correct
6 Correct 3 ms 3052 KB Output is correct
7 Correct 3 ms 3052 KB Output is correct
8 Correct 3 ms 3052 KB Output is correct
9 Correct 3 ms 3052 KB Output is correct
10 Correct 4 ms 3052 KB Output is correct
11 Correct 5 ms 3052 KB Output is correct
12 Correct 4 ms 3052 KB Output is correct
13 Correct 4 ms 3052 KB Output is correct
14 Correct 5 ms 3056 KB Output is correct
15 Correct 5 ms 3056 KB Output is correct
16 Correct 5 ms 3056 KB Output is correct
17 Correct 5 ms 3288 KB Output is correct
18 Correct 4 ms 3288 KB Output is correct
19 Correct 4 ms 3288 KB Output is correct
20 Correct 4 ms 3288 KB Output is correct
21 Correct 4 ms 3288 KB Output is correct
22 Correct 4 ms 3288 KB Output is correct
23 Correct 5 ms 3288 KB Output is correct
24 Correct 6 ms 3288 KB Output is correct
25 Correct 5 ms 3288 KB Output is correct
26 Correct 4 ms 3288 KB Output is correct
27 Correct 4 ms 3288 KB Output is correct
28 Correct 5 ms 3308 KB Output is correct
29 Correct 9 ms 3792 KB Output is correct
30 Correct 5 ms 3792 KB Output is correct
31 Correct 7 ms 3792 KB Output is correct
32 Correct 7 ms 3792 KB Output is correct
33 Correct 13 ms 4200 KB Output is correct
34 Correct 13 ms 4200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4200 KB Output is correct
2 Correct 3 ms 4200 KB Output is correct
3 Correct 4 ms 4200 KB Output is correct
4 Correct 4 ms 4200 KB Output is correct
5 Correct 3 ms 4200 KB Output is correct
6 Correct 3 ms 4200 KB Output is correct
7 Correct 4 ms 4200 KB Output is correct
8 Correct 3 ms 4200 KB Output is correct
9 Correct 4 ms 4200 KB Output is correct
10 Correct 3 ms 4200 KB Output is correct
11 Correct 4 ms 4200 KB Output is correct
12 Correct 4 ms 4200 KB Output is correct
13 Correct 4 ms 4200 KB Output is correct
14 Correct 6 ms 4200 KB Output is correct
15 Correct 6 ms 4200 KB Output is correct
16 Correct 4 ms 4200 KB Output is correct
17 Correct 6 ms 4200 KB Output is correct
18 Correct 5 ms 4200 KB Output is correct
19 Correct 5 ms 4200 KB Output is correct
20 Correct 5 ms 4200 KB Output is correct
21 Correct 4 ms 4200 KB Output is correct
22 Correct 4 ms 4200 KB Output is correct
23 Correct 4 ms 4200 KB Output is correct
24 Correct 5 ms 4200 KB Output is correct
25 Correct 5 ms 4200 KB Output is correct
26 Correct 4 ms 4200 KB Output is correct
27 Correct 4 ms 4200 KB Output is correct
28 Correct 5 ms 4200 KB Output is correct
29 Correct 10 ms 4200 KB Output is correct
30 Correct 6 ms 4200 KB Output is correct
31 Correct 6 ms 4200 KB Output is correct
32 Correct 5 ms 4200 KB Output is correct
33 Correct 12 ms 4200 KB Output is correct
34 Correct 12 ms 4200 KB Output is correct
35 Correct 22 ms 5356 KB Output is correct
36 Correct 6 ms 5356 KB Output is correct
37 Correct 25 ms 5996 KB Output is correct
38 Correct 30 ms 6380 KB Output is correct
39 Correct 30 ms 6380 KB Output is correct
40 Correct 35 ms 6380 KB Output is correct
41 Correct 31 ms 6380 KB Output is correct
42 Correct 9 ms 6380 KB Output is correct
43 Correct 8 ms 6380 KB Output is correct
44 Correct 9 ms 6380 KB Output is correct
45 Correct 35 ms 8812 KB Output is correct
46 Correct 33 ms 8812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8812 KB Output is correct
2 Correct 3 ms 8812 KB Output is correct
3 Correct 3 ms 8812 KB Output is correct
4 Correct 3 ms 8812 KB Output is correct
5 Correct 3 ms 8812 KB Output is correct
6 Correct 4 ms 8812 KB Output is correct
7 Correct 3 ms 8812 KB Output is correct
8 Correct 3 ms 8812 KB Output is correct
9 Correct 3 ms 8812 KB Output is correct
10 Correct 4 ms 8812 KB Output is correct
11 Correct 4 ms 8812 KB Output is correct
12 Correct 3 ms 8812 KB Output is correct
13 Correct 4 ms 8812 KB Output is correct
14 Correct 5 ms 8812 KB Output is correct
15 Correct 5 ms 8812 KB Output is correct
16 Correct 4 ms 8812 KB Output is correct
17 Correct 6 ms 8812 KB Output is correct
18 Correct 4 ms 8812 KB Output is correct
19 Correct 4 ms 8812 KB Output is correct
20 Correct 4 ms 8812 KB Output is correct
21 Correct 4 ms 8812 KB Output is correct
22 Correct 4 ms 8812 KB Output is correct
23 Correct 5 ms 8812 KB Output is correct
24 Correct 7 ms 8812 KB Output is correct
25 Correct 6 ms 8812 KB Output is correct
26 Correct 5 ms 8812 KB Output is correct
27 Correct 4 ms 8812 KB Output is correct
28 Correct 5 ms 8812 KB Output is correct
29 Correct 11 ms 8812 KB Output is correct
30 Correct 6 ms 8812 KB Output is correct
31 Correct 8 ms 8812 KB Output is correct
32 Correct 6 ms 8812 KB Output is correct
33 Correct 13 ms 8812 KB Output is correct
34 Correct 12 ms 8812 KB Output is correct
35 Correct 23 ms 8812 KB Output is correct
36 Correct 9 ms 8812 KB Output is correct
37 Correct 26 ms 8812 KB Output is correct
38 Correct 32 ms 8812 KB Output is correct
39 Correct 31 ms 8812 KB Output is correct
40 Correct 29 ms 8812 KB Output is correct
41 Correct 29 ms 8812 KB Output is correct
42 Correct 14 ms 8812 KB Output is correct
43 Correct 8 ms 8812 KB Output is correct
44 Correct 8 ms 8812 KB Output is correct
45 Correct 33 ms 8812 KB Output is correct
46 Correct 34 ms 8812 KB Output is correct
47 Correct 75 ms 13420 KB Output is correct
48 Correct 22 ms 13420 KB Output is correct
49 Correct 18 ms 13420 KB Output is correct
50 Correct 14 ms 13420 KB Output is correct
51 Correct 85 ms 13420 KB Output is correct
52 Correct 89 ms 13420 KB Output is correct
53 Correct 36 ms 13420 KB Output is correct
54 Correct 10 ms 13420 KB Output is correct
55 Correct 12 ms 13420 KB Output is correct
56 Correct 18 ms 13420 KB Output is correct
57 Correct 86 ms 13420 KB Output is correct
58 Correct 19 ms 13420 KB Output is correct
59 Correct 19 ms 13420 KB Output is correct
60 Correct 21 ms 13420 KB Output is correct
61 Correct 21 ms 13420 KB Output is correct
62 Correct 33 ms 13420 KB Output is correct
63 Correct 152 ms 26468 KB Output is correct
64 Correct 174 ms 29928 KB Output is correct
65 Correct 229 ms 39284 KB Output is correct
66 Correct 447 ms 64084 KB Output is correct
67 Correct 432 ms 64084 KB Output is correct