# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
74723 | 2018-09-07T03:06:29 Z | goodbaton | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 109 ms | 40520 KB |
#include <cstdio> #include <cstdlib> #include <vector> #include <set> #include <algorithm> #include <map> #include <queue> #include <stack> #include <cmath> using namespace std; typedef long long ll; #define SIZE 30000 #define INF 2000000000 int N,M,B[SIZE],P[SIZE],s,g,cost[SIZE]; vector<int> way[SIZE]; bool kaku[SIZE]; bool wayn[SIZE][1001]; int main(){ scanf("%d%d",&N,&M); for(int i=0;i<N;i++){ cost[i]=-INF; } for(int i=0;i<M;i++){ scanf("%d%d",&B[i],&P[i]); if(i==0){ s = B[i]; } if(i==1){ g = B[i]; } if(P[i]<=1000) if(wayn[B[i]][P[i]]) continue; way[B[i]].push_back(i); if(P[i]<=1000) wayn[B[i]][P[i]]=true; } priority_queue<pair<int,int> > pq; pq.push(make_pair(0,s)); while(!pq.empty()){ pair<int,int> p=pq.top(); pq.pop(); int now = p.second; if(now==g){ printf("%d\n",-p.first); return 0; } if(kaku[now]) continue; kaku[now]=true; for(int i=way[now].size()-1;i>=0;i--){ int doge = way[now][i]; for(int j=1;B[doge]+j*P[doge]<N;j++){ if(cost[now+j*P[doge]]<p.first-j){ pq.push(make_pair(p.first-j,now+j*P[doge])); cost[now+j*P[doge]]=p.first-j; } if(P[doge]<=1000) if(wayn[now+j*P[doge]][P[doge]]) break; } for(int j=1;B[doge]-j*P[doge]>=0;j++){ if(cost[now-j*P[doge]]<p.first-j){ pq.push(make_pair(p.first-j,now-j*P[doge])); cost[now-j*P[doge]]=p.first-j; } if(P[doge]<=1000) if(wayn[now-j*P[doge]][P[doge]]) break; } } } printf("-1\n"); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1016 KB | Output is correct |
2 | Correct | 2 ms | 1144 KB | Output is correct |
3 | Correct | 2 ms | 1256 KB | Output is correct |
4 | Correct | 2 ms | 1256 KB | Output is correct |
5 | Correct | 2 ms | 1256 KB | Output is correct |
6 | Correct | 2 ms | 1256 KB | Output is correct |
7 | Correct | 2 ms | 1256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1276 KB | Output is correct |
2 | Correct | 2 ms | 1280 KB | Output is correct |
3 | Correct | 2 ms | 1288 KB | Output is correct |
4 | Correct | 2 ms | 1292 KB | Output is correct |
5 | Correct | 3 ms | 1296 KB | Output is correct |
6 | Correct | 2 ms | 1300 KB | Output is correct |
7 | Correct | 2 ms | 1304 KB | Output is correct |
8 | Correct | 3 ms | 1364 KB | Output is correct |
9 | Correct | 2 ms | 1364 KB | Output is correct |
10 | Correct | 3 ms | 1444 KB | Output is correct |
11 | Correct | 4 ms | 1492 KB | Output is correct |
12 | Correct | 3 ms | 1504 KB | Output is correct |
13 | Correct | 3 ms | 1552 KB | Output is correct |
14 | Correct | 3 ms | 1580 KB | Output is correct |
15 | Correct | 3 ms | 1580 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1580 KB | Output is correct |
2 | Correct | 2 ms | 1580 KB | Output is correct |
3 | Correct | 3 ms | 1580 KB | Output is correct |
4 | Correct | 3 ms | 1580 KB | Output is correct |
5 | Correct | 3 ms | 1580 KB | Output is correct |
6 | Correct | 3 ms | 1580 KB | Output is correct |
7 | Correct | 2 ms | 1580 KB | Output is correct |
8 | Correct | 3 ms | 1692 KB | Output is correct |
9 | Correct | 2 ms | 1692 KB | Output is correct |
10 | Correct | 3 ms | 1716 KB | Output is correct |
11 | Correct | 3 ms | 1720 KB | Output is correct |
12 | Correct | 3 ms | 1720 KB | Output is correct |
13 | Correct | 3 ms | 1744 KB | Output is correct |
14 | Correct | 3 ms | 1756 KB | Output is correct |
15 | Correct | 3 ms | 1768 KB | Output is correct |
16 | Correct | 3 ms | 1840 KB | Output is correct |
17 | Correct | 5 ms | 2432 KB | Output is correct |
18 | Correct | 4 ms | 2960 KB | Output is correct |
19 | Correct | 4 ms | 2960 KB | Output is correct |
20 | Correct | 5 ms | 3700 KB | Output is correct |
21 | Correct | 4 ms | 3700 KB | Output is correct |
22 | Correct | 4 ms | 3700 KB | Output is correct |
23 | Correct | 5 ms | 3700 KB | Output is correct |
24 | Correct | 6 ms | 3700 KB | Output is correct |
25 | Correct | 5 ms | 3700 KB | Output is correct |
26 | Correct | 4 ms | 3700 KB | Output is correct |
27 | Correct | 4 ms | 3700 KB | Output is correct |
28 | Correct | 5 ms | 3700 KB | Output is correct |
29 | Correct | 4 ms | 3700 KB | Output is correct |
30 | Correct | 4 ms | 3700 KB | Output is correct |
31 | Correct | 5 ms | 3700 KB | Output is correct |
32 | Correct | 4 ms | 3700 KB | Output is correct |
33 | Correct | 5 ms | 3700 KB | Output is correct |
34 | Correct | 4 ms | 3700 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3700 KB | Output is correct |
2 | Correct | 3 ms | 3700 KB | Output is correct |
3 | Correct | 2 ms | 3700 KB | Output is correct |
4 | Correct | 2 ms | 3700 KB | Output is correct |
5 | Correct | 3 ms | 3700 KB | Output is correct |
6 | Correct | 3 ms | 3700 KB | Output is correct |
7 | Correct | 2 ms | 3700 KB | Output is correct |
8 | Correct | 3 ms | 3700 KB | Output is correct |
9 | Correct | 3 ms | 3700 KB | Output is correct |
10 | Correct | 3 ms | 3700 KB | Output is correct |
11 | Correct | 3 ms | 3700 KB | Output is correct |
12 | Correct | 3 ms | 3700 KB | Output is correct |
13 | Correct | 3 ms | 3700 KB | Output is correct |
14 | Correct | 3 ms | 3700 KB | Output is correct |
15 | Correct | 3 ms | 3700 KB | Output is correct |
16 | Correct | 3 ms | 3700 KB | Output is correct |
17 | Correct | 4 ms | 3700 KB | Output is correct |
18 | Correct | 4 ms | 3700 KB | Output is correct |
19 | Correct | 4 ms | 3700 KB | Output is correct |
20 | Correct | 5 ms | 4128 KB | Output is correct |
21 | Correct | 3 ms | 4128 KB | Output is correct |
22 | Correct | 4 ms | 4128 KB | Output is correct |
23 | Correct | 5 ms | 4128 KB | Output is correct |
24 | Correct | 6 ms | 4128 KB | Output is correct |
25 | Correct | 5 ms | 4128 KB | Output is correct |
26 | Correct | 4 ms | 4128 KB | Output is correct |
27 | Correct | 5 ms | 4128 KB | Output is correct |
28 | Correct | 5 ms | 4128 KB | Output is correct |
29 | Correct | 5 ms | 4128 KB | Output is correct |
30 | Correct | 4 ms | 4128 KB | Output is correct |
31 | Correct | 4 ms | 4128 KB | Output is correct |
32 | Correct | 18 ms | 4128 KB | Output is correct |
33 | Correct | 5 ms | 4128 KB | Output is correct |
34 | Correct | 4 ms | 4128 KB | Output is correct |
35 | Correct | 13 ms | 4312 KB | Output is correct |
36 | Correct | 5 ms | 4312 KB | Output is correct |
37 | Correct | 12 ms | 4956 KB | Output is correct |
38 | Correct | 17 ms | 5500 KB | Output is correct |
39 | Correct | 14 ms | 5716 KB | Output is correct |
40 | Correct | 14 ms | 6028 KB | Output is correct |
41 | Correct | 18 ms | 6292 KB | Output is correct |
42 | Correct | 9 ms | 6292 KB | Output is correct |
43 | Correct | 9 ms | 6292 KB | Output is correct |
44 | Correct | 11 ms | 6588 KB | Output is correct |
45 | Correct | 19 ms | 6588 KB | Output is correct |
46 | Correct | 14 ms | 6588 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 6588 KB | Output is correct |
2 | Correct | 2 ms | 6588 KB | Output is correct |
3 | Correct | 2 ms | 6588 KB | Output is correct |
4 | Correct | 2 ms | 6588 KB | Output is correct |
5 | Correct | 2 ms | 6588 KB | Output is correct |
6 | Correct | 2 ms | 6588 KB | Output is correct |
7 | Correct | 2 ms | 6588 KB | Output is correct |
8 | Correct | 3 ms | 6588 KB | Output is correct |
9 | Correct | 2 ms | 6588 KB | Output is correct |
10 | Correct | 3 ms | 6588 KB | Output is correct |
11 | Correct | 4 ms | 6588 KB | Output is correct |
12 | Correct | 3 ms | 6588 KB | Output is correct |
13 | Correct | 3 ms | 6588 KB | Output is correct |
14 | Correct | 3 ms | 6588 KB | Output is correct |
15 | Correct | 3 ms | 6588 KB | Output is correct |
16 | Correct | 3 ms | 6588 KB | Output is correct |
17 | Correct | 5 ms | 6588 KB | Output is correct |
18 | Correct | 4 ms | 6588 KB | Output is correct |
19 | Correct | 4 ms | 6588 KB | Output is correct |
20 | Correct | 4 ms | 7040 KB | Output is correct |
21 | Correct | 3 ms | 7040 KB | Output is correct |
22 | Correct | 4 ms | 7040 KB | Output is correct |
23 | Correct | 5 ms | 7040 KB | Output is correct |
24 | Correct | 6 ms | 7040 KB | Output is correct |
25 | Correct | 5 ms | 7040 KB | Output is correct |
26 | Correct | 4 ms | 7040 KB | Output is correct |
27 | Correct | 4 ms | 7040 KB | Output is correct |
28 | Correct | 5 ms | 7040 KB | Output is correct |
29 | Correct | 5 ms | 7040 KB | Output is correct |
30 | Correct | 4 ms | 7040 KB | Output is correct |
31 | Correct | 4 ms | 7040 KB | Output is correct |
32 | Correct | 4 ms | 7040 KB | Output is correct |
33 | Correct | 5 ms | 7040 KB | Output is correct |
34 | Correct | 4 ms | 7040 KB | Output is correct |
35 | Correct | 14 ms | 7252 KB | Output is correct |
36 | Correct | 5 ms | 7252 KB | Output is correct |
37 | Correct | 14 ms | 8104 KB | Output is correct |
38 | Correct | 18 ms | 8460 KB | Output is correct |
39 | Correct | 15 ms | 8676 KB | Output is correct |
40 | Correct | 16 ms | 8988 KB | Output is correct |
41 | Correct | 17 ms | 9288 KB | Output is correct |
42 | Correct | 9 ms | 9288 KB | Output is correct |
43 | Correct | 9 ms | 9288 KB | Output is correct |
44 | Correct | 11 ms | 9580 KB | Output is correct |
45 | Correct | 13 ms | 9580 KB | Output is correct |
46 | Correct | 13 ms | 9580 KB | Output is correct |
47 | Correct | 32 ms | 20708 KB | Output is correct |
48 | Correct | 17 ms | 20708 KB | Output is correct |
49 | Correct | 16 ms | 20708 KB | Output is correct |
50 | Correct | 11 ms | 20708 KB | Output is correct |
51 | Correct | 38 ms | 20708 KB | Output is correct |
52 | Correct | 40 ms | 20708 KB | Output is correct |
53 | Correct | 22 ms | 20708 KB | Output is correct |
54 | Correct | 12 ms | 20708 KB | Output is correct |
55 | Correct | 12 ms | 20708 KB | Output is correct |
56 | Correct | 55 ms | 40520 KB | Output is correct |
57 | Correct | 19 ms | 40520 KB | Output is correct |
58 | Correct | 18 ms | 40520 KB | Output is correct |
59 | Correct | 19 ms | 40520 KB | Output is correct |
60 | Correct | 20 ms | 40520 KB | Output is correct |
61 | Correct | 23 ms | 40520 KB | Output is correct |
62 | Correct | 30 ms | 40520 KB | Output is correct |
63 | Correct | 65 ms | 40520 KB | Output is correct |
64 | Correct | 58 ms | 40520 KB | Output is correct |
65 | Correct | 75 ms | 40520 KB | Output is correct |
66 | Correct | 109 ms | 40520 KB | Output is correct |
67 | Correct | 102 ms | 40520 KB | Output is correct |