답안 #30888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
30888 2017-07-31T11:43:00 Z Navick Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
1000 ms 33116 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;
map<pii, int> d;
vector<int> t[N];
bool vis[N];
deque<pii> q;

int main(){
	int n, m; cin >> n >> m;
	int sp, sb, se;

	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[{sp, sb}] = 0;

	while(!q.empty()){
		int p = q.front().F, b = q.front().S;
		int dis = d[{p, b}];
		q.pop_front();
		if(!vis[p]){
			for(auto l : t[p]){
				if(d.count({p, l}) == 0)
					d[{p, l}] = dis, q.push_front({p, l});
			}
			vis[p] = true;
		}
		if(p + b < n){
			if(d.count({p + b, b}) == 0)
				d[{p + b, b}] = dis + 1, q.push_back({p + b, b});
		}
		if(p - b >= 0){
			if(d.count({p - b, b}) == 0)
				d[{p - b, b}] = dis + 1, q.push_back({p - b, b});
		}
	}
	int mn = INF;
	for(int i=0; i<=n; i++){
		if(d.count({se, i}))
			mn = min(mn, d[{se, i}]);
	}
	if(mn < INF)
		cout << mn << endl;
	else cout << -1 << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2756 KB Output is correct
2 Correct 0 ms 2756 KB Output is correct
3 Correct 0 ms 2756 KB Output is correct
4 Correct 0 ms 2756 KB Output is correct
5 Correct 0 ms 2756 KB Output is correct
6 Correct 0 ms 2756 KB Output is correct
7 Correct 0 ms 2756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2756 KB Output is correct
2 Correct 0 ms 2756 KB Output is correct
3 Correct 0 ms 2756 KB Output is correct
4 Correct 0 ms 2756 KB Output is correct
5 Correct 0 ms 2756 KB Output is correct
6 Correct 0 ms 2756 KB Output is correct
7 Correct 0 ms 2756 KB Output is correct
8 Correct 0 ms 2756 KB Output is correct
9 Correct 0 ms 2756 KB Output is correct
10 Correct 0 ms 2888 KB Output is correct
11 Correct 3 ms 3020 KB Output is correct
12 Correct 0 ms 2756 KB Output is correct
13 Correct 0 ms 2756 KB Output is correct
14 Correct 3 ms 3152 KB Output is correct
15 Correct 3 ms 3152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2756 KB Output is correct
2 Correct 0 ms 2756 KB Output is correct
3 Correct 0 ms 2756 KB Output is correct
4 Correct 0 ms 2756 KB Output is correct
5 Correct 0 ms 2756 KB Output is correct
6 Correct 0 ms 2756 KB Output is correct
7 Correct 0 ms 2756 KB Output is correct
8 Correct 0 ms 2756 KB Output is correct
9 Correct 0 ms 2756 KB Output is correct
10 Correct 0 ms 2888 KB Output is correct
11 Correct 3 ms 3020 KB Output is correct
12 Correct 0 ms 2756 KB Output is correct
13 Correct 0 ms 2756 KB Output is correct
14 Correct 3 ms 3152 KB Output is correct
15 Correct 3 ms 3152 KB Output is correct
16 Correct 0 ms 2756 KB Output is correct
17 Correct 13 ms 3680 KB Output is correct
18 Correct 0 ms 2756 KB Output is correct
19 Correct 0 ms 2756 KB Output is correct
20 Correct 3 ms 3020 KB Output is correct
21 Correct 0 ms 2756 KB Output is correct
22 Correct 0 ms 2756 KB Output is correct
23 Correct 3 ms 3152 KB Output is correct
24 Correct 9 ms 3548 KB Output is correct
25 Correct 6 ms 3284 KB Output is correct
26 Correct 6 ms 3284 KB Output is correct
27 Correct 3 ms 3152 KB Output is correct
28 Correct 19 ms 4208 KB Output is correct
29 Correct 63 ms 6584 KB Output is correct
30 Correct 13 ms 3812 KB Output is correct
31 Correct 26 ms 4868 KB Output is correct
32 Correct 16 ms 4208 KB Output is correct
33 Correct 129 ms 10280 KB Output is correct
34 Correct 179 ms 10276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2756 KB Output is correct
2 Correct 0 ms 2756 KB Output is correct
3 Correct 0 ms 2756 KB Output is correct
4 Correct 0 ms 2756 KB Output is correct
5 Correct 0 ms 2756 KB Output is correct
6 Correct 0 ms 2756 KB Output is correct
7 Correct 0 ms 2756 KB Output is correct
8 Correct 0 ms 2756 KB Output is correct
9 Correct 0 ms 2756 KB Output is correct
10 Correct 0 ms 2888 KB Output is correct
11 Correct 3 ms 3020 KB Output is correct
12 Correct 0 ms 2756 KB Output is correct
13 Correct 0 ms 2756 KB Output is correct
14 Correct 3 ms 3152 KB Output is correct
15 Correct 3 ms 3152 KB Output is correct
16 Correct 0 ms 2756 KB Output is correct
17 Correct 13 ms 3680 KB Output is correct
18 Correct 0 ms 2756 KB Output is correct
19 Correct 0 ms 2756 KB Output is correct
20 Correct 0 ms 3020 KB Output is correct
21 Correct 0 ms 2756 KB Output is correct
22 Correct 0 ms 2756 KB Output is correct
23 Correct 0 ms 3152 KB Output is correct
24 Correct 13 ms 3548 KB Output is correct
25 Correct 6 ms 3284 KB Output is correct
26 Correct 6 ms 3284 KB Output is correct
27 Correct 3 ms 3152 KB Output is correct
28 Correct 16 ms 4208 KB Output is correct
29 Correct 66 ms 6584 KB Output is correct
30 Correct 13 ms 3812 KB Output is correct
31 Correct 23 ms 4868 KB Output is correct
32 Correct 19 ms 4208 KB Output is correct
33 Correct 166 ms 10280 KB Output is correct
34 Correct 173 ms 10276 KB Output is correct
35 Correct 153 ms 9356 KB Output is correct
36 Correct 16 ms 3940 KB Output is correct
37 Correct 386 ms 13712 KB Output is correct
38 Correct 353 ms 13052 KB Output is correct
39 Correct 346 ms 13052 KB Output is correct
40 Correct 333 ms 13048 KB Output is correct
41 Correct 336 ms 13052 KB Output is correct
42 Correct 16 ms 3364 KB Output is correct
43 Correct 16 ms 3364 KB Output is correct
44 Correct 19 ms 3132 KB Output is correct
45 Execution timed out 1000 ms 33116 KB Execution timed out
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2756 KB Output is correct
2 Correct 0 ms 2756 KB Output is correct
3 Correct 0 ms 2756 KB Output is correct
4 Correct 0 ms 2756 KB Output is correct
5 Correct 0 ms 2756 KB Output is correct
6 Correct 0 ms 2756 KB Output is correct
7 Correct 0 ms 2756 KB Output is correct
8 Correct 0 ms 2756 KB Output is correct
9 Correct 0 ms 2756 KB Output is correct
10 Correct 0 ms 2888 KB Output is correct
11 Correct 3 ms 3020 KB Output is correct
12 Correct 0 ms 2756 KB Output is correct
13 Correct 0 ms 2756 KB Output is correct
14 Correct 3 ms 3152 KB Output is correct
15 Correct 3 ms 3152 KB Output is correct
16 Correct 0 ms 2756 KB Output is correct
17 Correct 6 ms 3680 KB Output is correct
18 Correct 0 ms 2756 KB Output is correct
19 Correct 0 ms 2756 KB Output is correct
20 Correct 3 ms 3020 KB Output is correct
21 Correct 0 ms 2756 KB Output is correct
22 Correct 0 ms 2756 KB Output is correct
23 Correct 3 ms 3152 KB Output is correct
24 Correct 9 ms 3548 KB Output is correct
25 Correct 6 ms 3284 KB Output is correct
26 Correct 3 ms 3284 KB Output is correct
27 Correct 6 ms 3152 KB Output is correct
28 Correct 16 ms 4208 KB Output is correct
29 Correct 56 ms 6584 KB Output is correct
30 Correct 13 ms 3812 KB Output is correct
31 Correct 26 ms 4868 KB Output is correct
32 Correct 16 ms 4208 KB Output is correct
33 Correct 159 ms 10280 KB Output is correct
34 Correct 179 ms 10276 KB Output is correct
35 Correct 173 ms 9356 KB Output is correct
36 Correct 13 ms 3940 KB Output is correct
37 Correct 346 ms 13712 KB Output is correct
38 Correct 319 ms 13052 KB Output is correct
39 Correct 263 ms 13052 KB Output is correct
40 Correct 386 ms 13048 KB Output is correct
41 Correct 359 ms 13052 KB Output is correct
42 Correct 19 ms 3364 KB Output is correct
43 Correct 23 ms 3364 KB Output is correct
44 Correct 23 ms 3132 KB Output is correct
45 Execution timed out 1000 ms 33116 KB Execution timed out
46 Halted 0 ms 0 KB -