답안 #30890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
30890 2017-07-31T11:51:51 Z Navick Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
1000 ms 33148 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(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	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}];
		if(p == se)return cout << dis << '\n', 0;
		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 == se)
					return cout << dis + 1 << '\n', 0;
			}
		}
		if(p - b >= 0){
			if(d.count({p - b, b}) == 0){
				d[{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({se, i}))
			mn = min(mn, d[{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:68:12: warning: division by zero [-Wdiv-by-zero]
   cout << 1/0 << endl;
            ^
skyscraper.cpp:57:5: warning: 'se' may be used uninitialized in this function [-Wmaybe-uninitialized]
     if(p - b == se)
     ^
# 결과 실행 시간 메모리 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 3 ms 3316 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 3 ms 3316 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 3052 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 3052 KB Output is correct
21 Correct 0 ms 2920 KB Output is correct
22 Correct 0 ms 2920 KB Output is correct
23 Correct 3 ms 3184 KB Output is correct
24 Correct 6 ms 3316 KB Output is correct
25 Correct 0 ms 2920 KB Output is correct
26 Correct 0 ms 3052 KB Output is correct
27 Correct 0 ms 3184 KB Output is correct
28 Correct 13 ms 4240 KB Output is correct
29 Correct 49 ms 6748 KB Output is correct
30 Correct 6 ms 3976 KB Output is correct
31 Correct 23 ms 4900 KB Output is correct
32 Correct 16 ms 4372 KB Output is correct
33 Correct 173 ms 10444 KB Output is correct
34 Correct 66 ms 6880 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 3316 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 3052 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 3052 KB Output is correct
21 Correct 0 ms 2920 KB Output is correct
22 Correct 0 ms 2920 KB Output is correct
23 Correct 3 ms 3184 KB Output is correct
24 Correct 3 ms 3316 KB Output is correct
25 Correct 0 ms 2920 KB Output is correct
26 Correct 0 ms 3052 KB Output is correct
27 Correct 0 ms 3184 KB Output is correct
28 Correct 13 ms 4240 KB Output is correct
29 Correct 66 ms 6748 KB Output is correct
30 Correct 13 ms 3976 KB Output is correct
31 Correct 26 ms 4900 KB Output is correct
32 Correct 16 ms 4372 KB Output is correct
33 Correct 173 ms 10444 KB Output is correct
34 Correct 66 ms 6880 KB Output is correct
35 Correct 16 ms 4372 KB Output is correct
36 Correct 0 ms 3052 KB Output is correct
37 Correct 6 ms 3316 KB Output is correct
38 Correct 6 ms 3184 KB Output is correct
39 Correct 6 ms 3184 KB Output is correct
40 Correct 6 ms 3184 KB Output is correct
41 Correct 6 ms 3184 KB Output is correct
42 Correct 6 ms 3216 KB Output is correct
43 Correct 6 ms 3348 KB Output is correct
44 Correct 6 ms 3212 KB Output is correct
45 Execution timed out 1000 ms 33148 KB Execution timed out
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 3316 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 3052 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 3052 KB Output is correct
21 Correct 0 ms 2920 KB Output is correct
22 Correct 0 ms 2920 KB Output is correct
23 Correct 3 ms 3184 KB Output is correct
24 Correct 0 ms 3316 KB Output is correct
25 Correct 0 ms 2920 KB Output is correct
26 Correct 0 ms 3052 KB Output is correct
27 Correct 0 ms 3184 KB Output is correct
28 Correct 16 ms 4240 KB Output is correct
29 Correct 63 ms 6748 KB Output is correct
30 Correct 6 ms 3976 KB Output is correct
31 Correct 33 ms 4900 KB Output is correct
32 Correct 16 ms 4372 KB Output is correct
33 Correct 173 ms 10444 KB Output is correct
34 Correct 79 ms 6880 KB Output is correct
35 Correct 13 ms 4372 KB Output is correct
36 Correct 0 ms 3052 KB Output is correct
37 Correct 3 ms 3316 KB Output is correct
38 Correct 6 ms 3184 KB Output is correct
39 Correct 6 ms 3184 KB Output is correct
40 Correct 9 ms 3184 KB Output is correct
41 Correct 9 ms 3184 KB Output is correct
42 Correct 6 ms 3216 KB Output is correct
43 Correct 3 ms 3348 KB Output is correct
44 Correct 6 ms 3212 KB Output is correct
45 Execution timed out 1000 ms 33148 KB Execution timed out
46 Halted 0 ms 0 KB -