답안 #30892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
30892 2017-07-31T12:13:28 Z Navick Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 121436 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 3e4 + 10, M = 5e6, INF = 1e9;
unordered_map<int, int> d;
vector<int> t[N];
bool vis[N];
deque<pii> q;
int sp, sb, se;


inline ll gg(ll a, ll b){
	return a * N + b;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, m; cin >> n >> m;

	for(int i=0; i<m; i++){
		int p, b; cin >> p >> b;
		t[p].pb(b);
		if(i == 0)
			sp = p, sb = b;
		if(i == 1)
			se = p;
	}

	q.push_back({sp, sb});
	d[gg(sp, sb)] = 0;

	while(!q.empty()){
		int p = q.front().F, b = q.front().S;
		int dis = d[gg(p, b)];
		if(p == se)return cout << dis << '\n', 0;
		q.pop_front();
		if(!vis[p]){
			for(auto l : t[p]){
				if(d.count(gg(p, l)) == 0)
					d[gg(p, l)] = dis, q.push_front({p, l});
			}
			vis[p] = true;
		}
		if(p + b < n){
			if(d.count(gg(p + b, b)) == 0){
				d[gg(p + b, b)] = dis + 1, q.push_back({p + b, b});
				if(p + b == se)
					return cout << dis + 1 << '\n', 0;
			}
		}
		if(p - b >= 0){
			if(d.count(gg(p - b, b)) == 0){
				d[gg(p - b, b)] = dis + 1, q.push_back({p - b, b});
				if(p - b == se)
					return cout << dis + 1 << '\n', 0;
			}
		}
	}
	int mn = INF;
	for(int i=0; i<=n; i++){
		if(d.count(gg(se, i)))
			mn = min(mn, d[gg(se, i)]);
	}
	if(d.size() > 1e6)
		cout << 1/0 << endl;
	if(mn < INF)
		cout << mn << endl;
	else cout << -1 << endl;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:73:12: warning: division by zero [-Wdiv-by-zero]
   cout << 1/0 << endl;
            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2920 KB Output is correct
2 Correct 0 ms 2920 KB Output is correct
3 Correct 0 ms 2920 KB Output is correct
4 Correct 0 ms 2920 KB Output is correct
5 Correct 0 ms 2920 KB Output is correct
6 Correct 0 ms 2920 KB Output is correct
7 Correct 0 ms 2920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2920 KB Output is correct
2 Correct 0 ms 2920 KB Output is correct
3 Correct 0 ms 2920 KB Output is correct
4 Correct 0 ms 2920 KB Output is correct
5 Correct 0 ms 2920 KB Output is correct
6 Correct 0 ms 2920 KB Output is correct
7 Correct 0 ms 2920 KB Output is correct
8 Correct 0 ms 2920 KB Output is correct
9 Correct 0 ms 2920 KB Output is correct
10 Correct 0 ms 2920 KB Output is correct
11 Correct 0 ms 2920 KB Output is correct
12 Correct 0 ms 2920 KB Output is correct
13 Correct 0 ms 2920 KB Output is correct
14 Correct 0 ms 3200 KB Output is correct
15 Correct 0 ms 2920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2920 KB Output is correct
2 Correct 0 ms 2920 KB Output is correct
3 Correct 0 ms 2920 KB Output is correct
4 Correct 0 ms 2920 KB Output is correct
5 Correct 0 ms 2920 KB Output is correct
6 Correct 0 ms 2920 KB Output is correct
7 Correct 0 ms 2920 KB Output is correct
8 Correct 0 ms 2920 KB Output is correct
9 Correct 0 ms 2920 KB Output is correct
10 Correct 0 ms 2920 KB Output is correct
11 Correct 0 ms 2920 KB Output is correct
12 Correct 0 ms 2920 KB Output is correct
13 Correct 0 ms 2920 KB Output is correct
14 Correct 0 ms 3200 KB Output is correct
15 Correct 0 ms 2920 KB Output is correct
16 Correct 0 ms 2920 KB Output is correct
17 Correct 0 ms 3080 KB Output is correct
18 Correct 0 ms 2920 KB Output is correct
19 Correct 0 ms 2920 KB Output is correct
20 Correct 0 ms 3060 KB Output is correct
21 Correct 0 ms 2920 KB Output is correct
22 Correct 0 ms 2920 KB Output is correct
23 Correct 0 ms 3076 KB Output is correct
24 Correct 0 ms 3200 KB Output is correct
25 Correct 0 ms 2920 KB Output is correct
26 Correct 0 ms 3060 KB Output is correct
27 Correct 0 ms 3060 KB Output is correct
28 Correct 9 ms 3804 KB Output is correct
29 Correct 19 ms 5316 KB Output is correct
30 Correct 3 ms 3744 KB Output is correct
31 Correct 9 ms 4636 KB Output is correct
32 Correct 6 ms 3884 KB Output is correct
33 Correct 33 ms 7684 KB Output is correct
34 Correct 23 ms 6324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2920 KB Output is correct
2 Correct 0 ms 2920 KB Output is correct
3 Correct 0 ms 2920 KB Output is correct
4 Correct 0 ms 2920 KB Output is correct
5 Correct 0 ms 2920 KB Output is correct
6 Correct 0 ms 2920 KB Output is correct
7 Correct 0 ms 2920 KB Output is correct
8 Correct 0 ms 2920 KB Output is correct
9 Correct 0 ms 2920 KB Output is correct
10 Correct 0 ms 2920 KB Output is correct
11 Correct 0 ms 2920 KB Output is correct
12 Correct 0 ms 2920 KB Output is correct
13 Correct 0 ms 2920 KB Output is correct
14 Correct 3 ms 3200 KB Output is correct
15 Correct 0 ms 2920 KB Output is correct
16 Correct 0 ms 2920 KB Output is correct
17 Correct 0 ms 3080 KB Output is correct
18 Correct 0 ms 2920 KB Output is correct
19 Correct 0 ms 2920 KB Output is correct
20 Correct 0 ms 3060 KB Output is correct
21 Correct 0 ms 2920 KB Output is correct
22 Correct 0 ms 2920 KB Output is correct
23 Correct 0 ms 3076 KB Output is correct
24 Correct 3 ms 3200 KB Output is correct
25 Correct 0 ms 2920 KB Output is correct
26 Correct 0 ms 3060 KB Output is correct
27 Correct 0 ms 3060 KB Output is correct
28 Correct 3 ms 3804 KB Output is correct
29 Correct 19 ms 5316 KB Output is correct
30 Correct 6 ms 3744 KB Output is correct
31 Correct 6 ms 4636 KB Output is correct
32 Correct 6 ms 3884 KB Output is correct
33 Correct 33 ms 7684 KB Output is correct
34 Correct 16 ms 6324 KB Output is correct
35 Correct 13 ms 4068 KB Output is correct
36 Correct 0 ms 2920 KB Output is correct
37 Correct 0 ms 3204 KB Output is correct
38 Correct 6 ms 3184 KB Output is correct
39 Correct 6 ms 3184 KB Output is correct
40 Correct 0 ms 3184 KB Output is correct
41 Correct 6 ms 3184 KB Output is correct
42 Correct 3 ms 3084 KB Output is correct
43 Correct 6 ms 3216 KB Output is correct
44 Correct 6 ms 3212 KB Output is correct
45 Correct 193 ms 22284 KB Output is correct
46 Correct 103 ms 12824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2920 KB Output is correct
2 Correct 0 ms 2920 KB Output is correct
3 Correct 0 ms 2920 KB Output is correct
4 Correct 0 ms 2920 KB Output is correct
5 Correct 0 ms 2920 KB Output is correct
6 Correct 0 ms 2920 KB Output is correct
7 Correct 0 ms 2920 KB Output is correct
8 Correct 0 ms 2920 KB Output is correct
9 Correct 0 ms 2920 KB Output is correct
10 Correct 0 ms 2920 KB Output is correct
11 Correct 0 ms 2920 KB Output is correct
12 Correct 0 ms 2920 KB Output is correct
13 Correct 0 ms 2920 KB Output is correct
14 Correct 0 ms 3200 KB Output is correct
15 Correct 0 ms 2920 KB Output is correct
16 Correct 0 ms 2920 KB Output is correct
17 Correct 0 ms 3080 KB Output is correct
18 Correct 0 ms 2920 KB Output is correct
19 Correct 0 ms 2920 KB Output is correct
20 Correct 0 ms 3060 KB Output is correct
21 Correct 0 ms 2920 KB Output is correct
22 Correct 0 ms 2920 KB Output is correct
23 Correct 0 ms 3076 KB Output is correct
24 Correct 0 ms 3200 KB Output is correct
25 Correct 0 ms 2920 KB Output is correct
26 Correct 0 ms 3060 KB Output is correct
27 Correct 0 ms 3060 KB Output is correct
28 Correct 6 ms 3804 KB Output is correct
29 Correct 16 ms 5316 KB Output is correct
30 Correct 6 ms 3744 KB Output is correct
31 Correct 3 ms 4636 KB Output is correct
32 Correct 3 ms 3884 KB Output is correct
33 Correct 36 ms 7684 KB Output is correct
34 Correct 19 ms 6324 KB Output is correct
35 Correct 13 ms 4068 KB Output is correct
36 Correct 0 ms 2920 KB Output is correct
37 Correct 3 ms 3204 KB Output is correct
38 Correct 6 ms 3184 KB Output is correct
39 Correct 9 ms 3184 KB Output is correct
40 Correct 9 ms 3184 KB Output is correct
41 Correct 6 ms 3184 KB Output is correct
42 Correct 6 ms 3084 KB Output is correct
43 Correct 3 ms 3216 KB Output is correct
44 Correct 0 ms 3212 KB Output is correct
45 Correct 179 ms 22284 KB Output is correct
46 Correct 79 ms 12824 KB Output is correct
47 Correct 3 ms 3320 KB Output is correct
48 Correct 9 ms 3316 KB Output is correct
49 Correct 9 ms 3316 KB Output is correct
50 Correct 6 ms 3184 KB Output is correct
51 Correct 29 ms 5384 KB Output is correct
52 Correct 43 ms 5784 KB Output is correct
53 Correct 13 ms 3752 KB Output is correct
54 Correct 3 ms 3500 KB Output is correct
55 Correct 6 ms 3876 KB Output is correct
56 Correct 19 ms 5076 KB Output is correct
57 Correct 0 ms 2920 KB Output is correct
58 Correct 19 ms 6424 KB Output is correct
59 Correct 16 ms 5304 KB Output is correct
60 Correct 23 ms 5312 KB Output is correct
61 Correct 26 ms 5188 KB Output is correct
62 Correct 306 ms 21964 KB Output is correct
63 Execution timed out 1000 ms 121436 KB Execution timed out
64 Halted 0 ms 0 KB -