답안 #874652

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874652 2023-11-17T13:35:02 Z Iliya_ Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
764 ms 4300 KB
//IN THE NAME OF GOD
#include<bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
#define endl        '\n'
#define F           first
#define S           second
#define all(x)      x.begin(),x.end()
#define pb          push_back
using namespace std;
typedef long long ll; 

#pragma GCC target("avx2")
const int N = 3e4+7, inf = 1e9;
int a[N], p[N], d[N], mark[N];
vector<int> g[N];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q; 
int v,u;

void dij(int n){
     fill(d,d+n,inf);
     d[a[0]] = 0; 
     q.push({0,a[0]}); 
     while(q.size()){
          v = q.top().S;
          q.pop();
          if (v == a[1]) return;
          if (mark[v]) continue; 
          mark[v] = 1;
          for (int p : g[v]){
               for(int i=1; v+i*p<n; i++){
                    u = v + i * p;
                    if (d[u] > d[v] + i){
                         d[u] = d[v] + i;
                         q.push({d[u],u}); 
                    }
               }
               for(int i=1; v-i*p>=0; i++){
                    u = v - i*p;
                    if (d[u] > d[v] + i){
                         d[u] = d[v] + i;
                         q.push({d[u],u});
                    }
               }
          }
     }
}

int32_t main(){
     ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
     
     int n,m; cin >> n >> m; 
     for(int i=0; i<m; i++){
          cin >> a[i] >> p[i]; 
          g[a[i]].pb(p[i]);
     }
     dij(n); 
     cout << (d[a[1]] == inf ? -1 : d[a[1]]) << endl; 

     return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 0 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 0 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 0 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1184 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1112 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 4 ms 1368 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1160 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1112 KB Output is correct
26 Correct 1 ms 1112 KB Output is correct
27 Correct 1 ms 1116 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 2 ms 1372 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 1 ms 1116 KB Output is correct
33 Correct 2 ms 1368 KB Output is correct
34 Correct 2 ms 1368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 0 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 2 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 5 ms 1112 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1112 KB Output is correct
26 Correct 1 ms 1116 KB Output is correct
27 Correct 1 ms 1116 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 2 ms 1372 KB Output is correct
30 Correct 2 ms 1116 KB Output is correct
31 Correct 2 ms 1112 KB Output is correct
32 Correct 1 ms 1116 KB Output is correct
33 Correct 2 ms 1372 KB Output is correct
34 Correct 2 ms 1372 KB Output is correct
35 Correct 5 ms 1624 KB Output is correct
36 Correct 2 ms 1116 KB Output is correct
37 Correct 4 ms 1492 KB Output is correct
38 Correct 6 ms 1664 KB Output is correct
39 Correct 5 ms 1628 KB Output is correct
40 Correct 5 ms 1628 KB Output is correct
41 Correct 5 ms 1624 KB Output is correct
42 Correct 5 ms 1624 KB Output is correct
43 Correct 4 ms 1628 KB Output is correct
44 Correct 57 ms 1640 KB Output is correct
45 Correct 8 ms 1628 KB Output is correct
46 Correct 7 ms 1780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1112 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 2 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 4 ms 1368 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1112 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1116 KB Output is correct
27 Correct 1 ms 1116 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 3 ms 1368 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 1 ms 1112 KB Output is correct
33 Correct 3 ms 1372 KB Output is correct
34 Correct 2 ms 1372 KB Output is correct
35 Correct 7 ms 1628 KB Output is correct
36 Correct 1 ms 1112 KB Output is correct
37 Correct 6 ms 1624 KB Output is correct
38 Correct 5 ms 1628 KB Output is correct
39 Correct 5 ms 1540 KB Output is correct
40 Correct 5 ms 1624 KB Output is correct
41 Correct 5 ms 1628 KB Output is correct
42 Correct 3 ms 1628 KB Output is correct
43 Correct 4 ms 1628 KB Output is correct
44 Correct 53 ms 1624 KB Output is correct
45 Correct 5 ms 1624 KB Output is correct
46 Correct 5 ms 1628 KB Output is correct
47 Correct 7 ms 2264 KB Output is correct
48 Correct 5 ms 1884 KB Output is correct
49 Correct 4 ms 1884 KB Output is correct
50 Correct 3 ms 1628 KB Output is correct
51 Correct 11 ms 3596 KB Output is correct
52 Correct 11 ms 2776 KB Output is correct
53 Correct 6 ms 2396 KB Output is correct
54 Correct 2 ms 1628 KB Output is correct
55 Correct 2 ms 1628 KB Output is correct
56 Correct 764 ms 2836 KB Output is correct
57 Correct 3 ms 2008 KB Output is correct
58 Correct 749 ms 1988 KB Output is correct
59 Correct 6 ms 2140 KB Output is correct
60 Correct 6 ms 2152 KB Output is correct
61 Correct 6 ms 2136 KB Output is correct
62 Correct 7 ms 2856 KB Output is correct
63 Correct 24 ms 3224 KB Output is correct
64 Correct 25 ms 4048 KB Output is correct
65 Correct 30 ms 4056 KB Output is correct
66 Correct 43 ms 4112 KB Output is correct
67 Correct 31 ms 4300 KB Output is correct