# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
420101 | 2021-06-08T05:49:39 Z | Dymo | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 605 ms | 17720 KB |
#include<bits/stdc++.h> using namespace std; #define ll int #define pll pair<ll,ll> #define ff first #define ss second #define pb push_back #define endl "\n" const ll maxn=3e4+10; const ll mod =1e9+7 ; const ll base=100; ll b[maxn]; ll p[maxn]; ll dp[maxn][base+3]; bool dd[maxn]; vector<ll> adj[maxn]; vector<ll> adj1[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (fopen("t.inp", "r")) { freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll n, m ; cin>> n>> m; ll st; ll ed; for (int i=1;i<=m;i++) { cin>>b[i]>>p[i]; b[i]++; if (i==1) st=b[i]; if (i==2) ed=b[i]; if (p[i]<=base) { adj[b[i]].pb(p[i]); } else { adj1[b[i]].pb(p[i]); } } priority_queue<pair<ll,pll>,vector<pair<ll,pll>>, greater<pair<ll,pll>>> q; for (int i=1;i<=n;i++) for (int j=0;j<=base;j++) dp[i][j]=1e9; dp[st][0]=0; q.push(make_pair(dp[st][0],make_pair(st,0))); while (!q.empty()) { auto p=q.top(); q.pop(); if (p.ff!=dp[p.ss.ff][p.ss.ss]) continue; ll t=p.ss.ss; ll u=p.ss.ff; if (!dd[u]) { dd[u]=1; for (auto to:adj[u]) { if (dp[u][to]>dp[u][t]) { dp[u][to]=dp[u][t]; q.push(make_pair(dp[u][to],make_pair(u,to))); } } for (auto to:adj1[u]) { for (int j=(u%to ? u%to : to);j<=n;j+=to) { if (dp[j][0]>dp[u][t]+abs(u-j)/to) { dp[j][0]=dp[u][t]+abs(u-j)/to; q.push(make_pair(dp[j][0],make_pair(j,0))); } } } } for (int j=-1;j<=1;j+=2) { ll nxt=u+j*t; if (nxt>=1&&nxt<=n&&dp[nxt][t]>dp[u][t]+1) { dp[nxt][t]=dp[u][t]+1; q.push(make_pair(dp[nxt][t],make_pair(nxt,t))); } } } ll h=1e9; for (int j=0;j<=base;j++) h=min(h,dp[ed][j]); if (h==1e9) h=-1; cout <<h<<endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1740 KB | Output is correct |
2 | Correct | 2 ms | 1732 KB | Output is correct |
3 | Correct | 1 ms | 1740 KB | Output is correct |
4 | Correct | 1 ms | 1740 KB | Output is correct |
5 | Correct | 1 ms | 1740 KB | Output is correct |
6 | Correct | 1 ms | 1740 KB | Output is correct |
7 | Correct | 2 ms | 1740 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1732 KB | Output is correct |
2 | Correct | 1 ms | 1728 KB | Output is correct |
3 | Correct | 1 ms | 1740 KB | Output is correct |
4 | Correct | 1 ms | 1740 KB | Output is correct |
5 | Correct | 2 ms | 1740 KB | Output is correct |
6 | Correct | 1 ms | 1740 KB | Output is correct |
7 | Correct | 1 ms | 1740 KB | Output is correct |
8 | Correct | 1 ms | 1740 KB | Output is correct |
9 | Correct | 1 ms | 1740 KB | Output is correct |
10 | Correct | 2 ms | 1740 KB | Output is correct |
11 | Correct | 2 ms | 1868 KB | Output is correct |
12 | Correct | 2 ms | 1740 KB | Output is correct |
13 | Correct | 2 ms | 1740 KB | Output is correct |
14 | Correct | 3 ms | 1868 KB | Output is correct |
15 | Correct | 2 ms | 1868 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1740 KB | Output is correct |
2 | Correct | 1 ms | 1740 KB | Output is correct |
3 | Correct | 1 ms | 1740 KB | Output is correct |
4 | Correct | 2 ms | 1728 KB | Output is correct |
5 | Correct | 1 ms | 1740 KB | Output is correct |
6 | Correct | 1 ms | 1740 KB | Output is correct |
7 | Correct | 1 ms | 1740 KB | Output is correct |
8 | Correct | 1 ms | 1740 KB | Output is correct |
9 | Correct | 2 ms | 1740 KB | Output is correct |
10 | Correct | 2 ms | 1740 KB | Output is correct |
11 | Correct | 3 ms | 1876 KB | Output is correct |
12 | Correct | 2 ms | 1740 KB | Output is correct |
13 | Correct | 2 ms | 1740 KB | Output is correct |
14 | Correct | 3 ms | 1868 KB | Output is correct |
15 | Correct | 3 ms | 1868 KB | Output is correct |
16 | Correct | 2 ms | 1740 KB | Output is correct |
17 | Correct | 3 ms | 2124 KB | Output is correct |
18 | Correct | 2 ms | 2380 KB | Output is correct |
19 | Correct | 2 ms | 2508 KB | Output is correct |
20 | Correct | 2 ms | 2636 KB | Output is correct |
21 | Correct | 2 ms | 1868 KB | Output is correct |
22 | Correct | 2 ms | 2380 KB | Output is correct |
23 | Correct | 3 ms | 2380 KB | Output is correct |
24 | Correct | 4 ms | 2508 KB | Output is correct |
25 | Correct | 3 ms | 2508 KB | Output is correct |
26 | Correct | 3 ms | 2508 KB | Output is correct |
27 | Correct | 2 ms | 2508 KB | Output is correct |
28 | Correct | 3 ms | 2636 KB | Output is correct |
29 | Correct | 9 ms | 2508 KB | Output is correct |
30 | Correct | 4 ms | 2508 KB | Output is correct |
31 | Correct | 5 ms | 2508 KB | Output is correct |
32 | Correct | 4 ms | 2508 KB | Output is correct |
33 | Correct | 18 ms | 2648 KB | Output is correct |
34 | Correct | 18 ms | 2644 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1740 KB | Output is correct |
2 | Correct | 2 ms | 1740 KB | Output is correct |
3 | Correct | 1 ms | 1740 KB | Output is correct |
4 | Correct | 2 ms | 1740 KB | Output is correct |
5 | Correct | 1 ms | 1740 KB | Output is correct |
6 | Correct | 1 ms | 1740 KB | Output is correct |
7 | Correct | 1 ms | 1692 KB | Output is correct |
8 | Correct | 2 ms | 1728 KB | Output is correct |
9 | Correct | 1 ms | 1740 KB | Output is correct |
10 | Correct | 2 ms | 1740 KB | Output is correct |
11 | Correct | 3 ms | 1868 KB | Output is correct |
12 | Correct | 2 ms | 1740 KB | Output is correct |
13 | Correct | 2 ms | 1740 KB | Output is correct |
14 | Correct | 2 ms | 1868 KB | Output is correct |
15 | Correct | 2 ms | 1868 KB | Output is correct |
16 | Correct | 2 ms | 1736 KB | Output is correct |
17 | Correct | 3 ms | 2124 KB | Output is correct |
18 | Correct | 2 ms | 2380 KB | Output is correct |
19 | Correct | 2 ms | 2508 KB | Output is correct |
20 | Correct | 3 ms | 2636 KB | Output is correct |
21 | Correct | 2 ms | 1868 KB | Output is correct |
22 | Correct | 3 ms | 2380 KB | Output is correct |
23 | Correct | 3 ms | 2380 KB | Output is correct |
24 | Correct | 3 ms | 2508 KB | Output is correct |
25 | Correct | 3 ms | 2508 KB | Output is correct |
26 | Correct | 3 ms | 2508 KB | Output is correct |
27 | Correct | 2 ms | 2508 KB | Output is correct |
28 | Correct | 3 ms | 2636 KB | Output is correct |
29 | Correct | 9 ms | 2508 KB | Output is correct |
30 | Correct | 4 ms | 2508 KB | Output is correct |
31 | Correct | 6 ms | 2504 KB | Output is correct |
32 | Correct | 5 ms | 2500 KB | Output is correct |
33 | Correct | 17 ms | 2648 KB | Output is correct |
34 | Correct | 20 ms | 2636 KB | Output is correct |
35 | Correct | 16 ms | 3000 KB | Output is correct |
36 | Correct | 5 ms | 2252 KB | Output is correct |
37 | Correct | 20 ms | 3188 KB | Output is correct |
38 | Correct | 22 ms | 3348 KB | Output is correct |
39 | Correct | 22 ms | 3404 KB | Output is correct |
40 | Correct | 24 ms | 3456 KB | Output is correct |
41 | Correct | 21 ms | 3276 KB | Output is correct |
42 | Correct | 10 ms | 3148 KB | Output is correct |
43 | Correct | 7 ms | 3148 KB | Output is correct |
44 | Correct | 8 ms | 3132 KB | Output is correct |
45 | Correct | 37 ms | 3532 KB | Output is correct |
46 | Correct | 38 ms | 3532 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1740 KB | Output is correct |
2 | Correct | 1 ms | 1740 KB | Output is correct |
3 | Correct | 1 ms | 1740 KB | Output is correct |
4 | Correct | 2 ms | 1740 KB | Output is correct |
5 | Correct | 1 ms | 1740 KB | Output is correct |
6 | Correct | 2 ms | 1740 KB | Output is correct |
7 | Correct | 2 ms | 1740 KB | Output is correct |
8 | Correct | 1 ms | 1740 KB | Output is correct |
9 | Correct | 2 ms | 1740 KB | Output is correct |
10 | Correct | 2 ms | 1732 KB | Output is correct |
11 | Correct | 2 ms | 1868 KB | Output is correct |
12 | Correct | 2 ms | 1736 KB | Output is correct |
13 | Correct | 2 ms | 1740 KB | Output is correct |
14 | Correct | 3 ms | 1868 KB | Output is correct |
15 | Correct | 3 ms | 1868 KB | Output is correct |
16 | Correct | 2 ms | 1740 KB | Output is correct |
17 | Correct | 4 ms | 2124 KB | Output is correct |
18 | Correct | 2 ms | 2380 KB | Output is correct |
19 | Correct | 3 ms | 2508 KB | Output is correct |
20 | Correct | 3 ms | 2636 KB | Output is correct |
21 | Correct | 2 ms | 1868 KB | Output is correct |
22 | Correct | 2 ms | 2376 KB | Output is correct |
23 | Correct | 2 ms | 2380 KB | Output is correct |
24 | Correct | 4 ms | 2508 KB | Output is correct |
25 | Correct | 3 ms | 2508 KB | Output is correct |
26 | Correct | 3 ms | 2508 KB | Output is correct |
27 | Correct | 3 ms | 2508 KB | Output is correct |
28 | Correct | 3 ms | 2636 KB | Output is correct |
29 | Correct | 9 ms | 2600 KB | Output is correct |
30 | Correct | 4 ms | 2508 KB | Output is correct |
31 | Correct | 7 ms | 2512 KB | Output is correct |
32 | Correct | 5 ms | 2460 KB | Output is correct |
33 | Correct | 17 ms | 2644 KB | Output is correct |
34 | Correct | 17 ms | 2636 KB | Output is correct |
35 | Correct | 15 ms | 3020 KB | Output is correct |
36 | Correct | 5 ms | 2252 KB | Output is correct |
37 | Correct | 20 ms | 3148 KB | Output is correct |
38 | Correct | 25 ms | 3404 KB | Output is correct |
39 | Correct | 20 ms | 3396 KB | Output is correct |
40 | Correct | 21 ms | 3332 KB | Output is correct |
41 | Correct | 21 ms | 3276 KB | Output is correct |
42 | Correct | 7 ms | 3148 KB | Output is correct |
43 | Correct | 7 ms | 3148 KB | Output is correct |
44 | Correct | 7 ms | 3148 KB | Output is correct |
45 | Correct | 37 ms | 3532 KB | Output is correct |
46 | Correct | 38 ms | 3452 KB | Output is correct |
47 | Correct | 72 ms | 8016 KB | Output is correct |
48 | Correct | 17 ms | 11980 KB | Output is correct |
49 | Correct | 17 ms | 12748 KB | Output is correct |
50 | Correct | 12 ms | 13644 KB | Output is correct |
51 | Correct | 58 ms | 15436 KB | Output is correct |
52 | Correct | 60 ms | 15416 KB | Output is correct |
53 | Correct | 24 ms | 14888 KB | Output is correct |
54 | Correct | 9 ms | 13772 KB | Output is correct |
55 | Correct | 10 ms | 13760 KB | Output is correct |
56 | Correct | 19 ms | 15180 KB | Output is correct |
57 | Correct | 82 ms | 13976 KB | Output is correct |
58 | Correct | 18 ms | 14412 KB | Output is correct |
59 | Correct | 20 ms | 14540 KB | Output is correct |
60 | Correct | 29 ms | 14540 KB | Output is correct |
61 | Correct | 25 ms | 14472 KB | Output is correct |
62 | Correct | 41 ms | 15124 KB | Output is correct |
63 | Correct | 56 ms | 16068 KB | Output is correct |
64 | Correct | 63 ms | 16068 KB | Output is correct |
65 | Correct | 80 ms | 17600 KB | Output is correct |
66 | Correct | 529 ms | 17720 KB | Output is correct |
67 | Correct | 605 ms | 17680 KB | Output is correct |