답안 #939177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939177 2024-03-06T06:30:47 Z a_l_i_r_e_z_a Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
156 ms 94340 KB
// In the name of God
// Hope is last to die
 
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
#define pb push_back
#define int long long
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
 
const int maxn = 3e4 + 5, maxd = 1e6 + 5;
const int inf = 1e9 + 7;
int n, m, s, t, d[maxn];
vector<int> vec[maxn], asli[maxd];
vector<pii> adj[maxn];
bool mark[maxn];
 
void dij(){
    memset(d, 63, sizeof d);
    d[s] = 0;
    asli[0].pb(s);
    for(int i = 0; i < maxd; i++){
        for(auto v: asli[i]){
            for(auto [u, w]: adj[v]){
                if(d[u] > d[v] + w){
                    d[u] = d[v] + w;
                    asli[d[u]].pb(u);
                }
            }
        }
    }
}
 
int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int b, p; cin >> b >> p;
        if(p < n) vec[p].pb(b);
        if(i == 0) s = b;
        if(i == 1) t = b;
    }
    for(int p = 1; p < n; p++){
        sort(all(vec[p]));
        vec[p].resize(unique(all(vec[p])) - vec[p].begin());
        for(auto u: vec[p]) mark[u] = 1;
        for(auto &i: vec[p]){
            if(!mark[i]) continue;
            for(int j = i - p; j >= 0; j -= p){
                adj[i].pb(mp(j, (i - j) / p));
                if(mark[j]) break;
            }
            for(int j = i + p; j < n; j += p){
                adj[i].pb(mp(j, (j - i) / p));
                if(mark[j]) break;
            }
        }
        for(auto u: vec[p]) mark[u] = 0;
    }
    dij();
    if(d[t] >= inf) cout << -1 << '\n';
    else cout << d[t] << '\n';
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 25432 KB Output is correct
2 Correct 7 ms 25436 KB Output is correct
3 Correct 8 ms 25584 KB Output is correct
4 Correct 7 ms 25436 KB Output is correct
5 Correct 7 ms 25436 KB Output is correct
6 Correct 8 ms 25432 KB Output is correct
7 Correct 7 ms 25432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 25436 KB Output is correct
2 Correct 8 ms 25436 KB Output is correct
3 Correct 8 ms 25436 KB Output is correct
4 Correct 7 ms 25432 KB Output is correct
5 Correct 7 ms 25436 KB Output is correct
6 Correct 7 ms 25436 KB Output is correct
7 Correct 8 ms 25436 KB Output is correct
8 Correct 8 ms 25436 KB Output is correct
9 Correct 8 ms 25420 KB Output is correct
10 Correct 8 ms 25436 KB Output is correct
11 Correct 8 ms 25436 KB Output is correct
12 Correct 8 ms 25436 KB Output is correct
13 Correct 8 ms 25432 KB Output is correct
14 Correct 8 ms 25436 KB Output is correct
15 Correct 8 ms 25692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 25432 KB Output is correct
2 Correct 7 ms 25436 KB Output is correct
3 Correct 8 ms 25436 KB Output is correct
4 Correct 7 ms 25588 KB Output is correct
5 Correct 7 ms 25588 KB Output is correct
6 Correct 7 ms 25436 KB Output is correct
7 Correct 8 ms 25432 KB Output is correct
8 Correct 8 ms 25432 KB Output is correct
9 Correct 10 ms 25436 KB Output is correct
10 Correct 8 ms 25436 KB Output is correct
11 Correct 8 ms 25436 KB Output is correct
12 Correct 8 ms 25436 KB Output is correct
13 Correct 8 ms 25632 KB Output is correct
14 Correct 8 ms 25420 KB Output is correct
15 Correct 9 ms 25436 KB Output is correct
16 Correct 7 ms 25436 KB Output is correct
17 Correct 9 ms 25692 KB Output is correct
18 Correct 9 ms 25436 KB Output is correct
19 Correct 8 ms 25660 KB Output is correct
20 Correct 7 ms 25692 KB Output is correct
21 Correct 7 ms 25432 KB Output is correct
22 Correct 8 ms 25432 KB Output is correct
23 Correct 8 ms 25692 KB Output is correct
24 Correct 8 ms 25692 KB Output is correct
25 Correct 8 ms 25692 KB Output is correct
26 Correct 8 ms 25692 KB Output is correct
27 Correct 8 ms 25692 KB Output is correct
28 Correct 8 ms 25672 KB Output is correct
29 Correct 9 ms 26204 KB Output is correct
30 Correct 8 ms 25692 KB Output is correct
31 Correct 9 ms 25948 KB Output is correct
32 Correct 8 ms 25908 KB Output is correct
33 Correct 10 ms 26972 KB Output is correct
34 Correct 10 ms 26968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 25436 KB Output is correct
2 Correct 8 ms 25592 KB Output is correct
3 Correct 7 ms 25436 KB Output is correct
4 Correct 9 ms 25436 KB Output is correct
5 Correct 8 ms 25436 KB Output is correct
6 Correct 8 ms 25436 KB Output is correct
7 Correct 7 ms 25436 KB Output is correct
8 Correct 7 ms 25592 KB Output is correct
9 Correct 8 ms 25432 KB Output is correct
10 Correct 8 ms 25436 KB Output is correct
11 Correct 8 ms 25436 KB Output is correct
12 Correct 9 ms 25620 KB Output is correct
13 Correct 7 ms 25436 KB Output is correct
14 Correct 8 ms 25436 KB Output is correct
15 Correct 8 ms 25436 KB Output is correct
16 Correct 8 ms 25436 KB Output is correct
17 Correct 8 ms 25676 KB Output is correct
18 Correct 8 ms 25524 KB Output is correct
19 Correct 8 ms 25436 KB Output is correct
20 Correct 8 ms 25736 KB Output is correct
21 Correct 10 ms 25436 KB Output is correct
22 Correct 8 ms 25432 KB Output is correct
23 Correct 9 ms 25692 KB Output is correct
24 Correct 8 ms 25692 KB Output is correct
25 Correct 8 ms 25664 KB Output is correct
26 Correct 9 ms 25692 KB Output is correct
27 Correct 8 ms 25744 KB Output is correct
28 Correct 8 ms 25908 KB Output is correct
29 Correct 9 ms 26260 KB Output is correct
30 Correct 10 ms 25692 KB Output is correct
31 Correct 8 ms 25928 KB Output is correct
32 Correct 8 ms 25688 KB Output is correct
33 Correct 11 ms 26972 KB Output is correct
34 Correct 11 ms 26972 KB Output is correct
35 Correct 13 ms 26716 KB Output is correct
36 Correct 9 ms 25692 KB Output is correct
37 Correct 13 ms 27740 KB Output is correct
38 Correct 15 ms 27668 KB Output is correct
39 Correct 14 ms 27740 KB Output is correct
40 Correct 15 ms 27700 KB Output is correct
41 Correct 15 ms 27736 KB Output is correct
42 Correct 11 ms 25820 KB Output is correct
43 Correct 11 ms 25820 KB Output is correct
44 Correct 11 ms 25824 KB Output is correct
45 Correct 19 ms 30300 KB Output is correct
46 Correct 19 ms 30388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 25436 KB Output is correct
2 Correct 8 ms 25436 KB Output is correct
3 Correct 7 ms 25436 KB Output is correct
4 Correct 8 ms 25436 KB Output is correct
5 Correct 7 ms 25436 KB Output is correct
6 Correct 7 ms 25436 KB Output is correct
7 Correct 8 ms 25688 KB Output is correct
8 Correct 8 ms 25436 KB Output is correct
9 Correct 7 ms 25436 KB Output is correct
10 Correct 7 ms 25436 KB Output is correct
11 Correct 8 ms 25436 KB Output is correct
12 Correct 8 ms 25616 KB Output is correct
13 Correct 9 ms 25436 KB Output is correct
14 Correct 8 ms 25436 KB Output is correct
15 Correct 8 ms 25432 KB Output is correct
16 Correct 8 ms 25432 KB Output is correct
17 Correct 9 ms 25664 KB Output is correct
18 Correct 8 ms 25680 KB Output is correct
19 Correct 8 ms 25684 KB Output is correct
20 Correct 8 ms 25692 KB Output is correct
21 Correct 8 ms 25436 KB Output is correct
22 Correct 8 ms 25436 KB Output is correct
23 Correct 10 ms 25688 KB Output is correct
24 Correct 8 ms 25692 KB Output is correct
25 Correct 8 ms 25796 KB Output is correct
26 Correct 8 ms 25692 KB Output is correct
27 Correct 8 ms 25692 KB Output is correct
28 Correct 9 ms 25692 KB Output is correct
29 Correct 9 ms 26192 KB Output is correct
30 Correct 8 ms 25692 KB Output is correct
31 Correct 9 ms 25944 KB Output is correct
32 Correct 9 ms 25692 KB Output is correct
33 Correct 11 ms 26972 KB Output is correct
34 Correct 11 ms 26968 KB Output is correct
35 Correct 15 ms 26716 KB Output is correct
36 Correct 9 ms 25692 KB Output is correct
37 Correct 16 ms 27912 KB Output is correct
38 Correct 18 ms 27740 KB Output is correct
39 Correct 18 ms 27628 KB Output is correct
40 Correct 15 ms 27484 KB Output is correct
41 Correct 16 ms 27740 KB Output is correct
42 Correct 11 ms 25820 KB Output is correct
43 Correct 11 ms 25824 KB Output is correct
44 Correct 13 ms 25824 KB Output is correct
45 Correct 19 ms 30300 KB Output is correct
46 Correct 19 ms 30556 KB Output is correct
47 Correct 30 ms 34640 KB Output is correct
48 Correct 22 ms 28376 KB Output is correct
49 Correct 15 ms 27484 KB Output is correct
50 Correct 14 ms 27228 KB Output is correct
51 Correct 26 ms 30680 KB Output is correct
52 Correct 25 ms 31016 KB Output is correct
53 Correct 17 ms 27756 KB Output is correct
54 Correct 10 ms 26204 KB Output is correct
55 Correct 11 ms 26716 KB Output is correct
56 Correct 17 ms 27608 KB Output is correct
57 Correct 23 ms 35420 KB Output is correct
58 Correct 14 ms 27356 KB Output is correct
59 Correct 14 ms 27740 KB Output is correct
60 Correct 17 ms 28376 KB Output is correct
61 Correct 14 ms 27740 KB Output is correct
62 Correct 23 ms 31700 KB Output is correct
63 Correct 46 ms 48976 KB Output is correct
64 Correct 56 ms 55624 KB Output is correct
65 Correct 69 ms 66892 KB Output is correct
66 Correct 133 ms 94084 KB Output is correct
67 Correct 156 ms 94340 KB Output is correct