답안 #675343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
675343 2022-12-27T04:58:21 Z Cookie Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
182 ms 84476 KB
#include<bits/stdc++.h>
 
using namespace std;
#include<fstream>
 
#define ll long long
#define vt vector
#define pb push_back
#define fi first
#define se second
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
typedef unsigned long long ull;
#define pii pair<int, int>
#define pll pair<ll, ll>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
const ll mod=  1e9 + 7;
const int mxk = 1e3, sq = 750, mxn = 3e4;
const ll inf = -1e18;
int n, m;
vt<pii>adj[mxn + 1];
int b[mxn + 1], p[mxn + 1];
set<int>s[mxn + 1];
map<int, int>alr[mxn + 1];
ll d[mxn + 1];
struct ch{
    int u; ll d;
};
struct cmp{
    bool operator ()(const ch &a, const ch &b){
        return(a.d > b.d);
    }
};

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    forr(i, 0, m){
        cin >> b[i] >> p[i];
        s[b[i]].insert(p[i]);
    }
    forr(i, 0, m){
        if(alr[b[i]][p[i]])continue;
        alr[b[i]][p[i]] = true;
        int pos = b[i];
        for(int j = pos - p[i]; j >= 0; j -= p[i]){
            adj[pos].pb({j, (pos - j) / p[i]});
            //cout << pos << ' ' << j << " ";
            if(s[j].count(p[i]))break;
        }
        for(int j = pos + p[i]; j < n; j += p[i]){
            adj[pos].pb({j, (j - pos) / p[i]});
            
            if(s[j].count(p[i]))break;
        }
    }
    for(int i = 0; i < n; i++)d[i] = 1e18;
    priority_queue<ch, vt<ch>, cmp>pq; d[b[0]] = 0; pq.push({b[0], d[b[0]]});
    while(pq.size()){
        auto [u, dd] = pq.top(); pq.pop();
        
        if(d[u] != dd)continue;
        if(u == b[1]){
            cout << d[u];
            return(0);
        }
        for(auto [v, w]: adj[u]){
            if(d[u] + w < d[v]){
                d[v] = d[u] + w;
                pq.push({v, d[v]});
            }
        }
    }
    cout << -1;
    return(0);
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:61:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |         auto [u, dd] = pq.top(); pq.pop();
      |              ^
skyscraper.cpp:68:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   68 |         for(auto [v, w]: adj[u]){
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 2 ms 3796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 2 ms 3796 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 3 ms 4052 KB Output is correct
12 Correct 3 ms 3796 KB Output is correct
13 Correct 3 ms 3796 KB Output is correct
14 Correct 3 ms 4052 KB Output is correct
15 Correct 3 ms 4052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 2 ms 3796 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 3 ms 4052 KB Output is correct
12 Correct 2 ms 3796 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 3 ms 4052 KB Output is correct
15 Correct 3 ms 4052 KB Output is correct
16 Correct 2 ms 3924 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 3 ms 3924 KB Output is correct
19 Correct 3 ms 3924 KB Output is correct
20 Correct 4 ms 4092 KB Output is correct
21 Correct 3 ms 3924 KB Output is correct
22 Correct 3 ms 3924 KB Output is correct
23 Correct 3 ms 4052 KB Output is correct
24 Correct 4 ms 4180 KB Output is correct
25 Correct 3 ms 4180 KB Output is correct
26 Correct 2 ms 3924 KB Output is correct
27 Correct 2 ms 3924 KB Output is correct
28 Correct 3 ms 4308 KB Output is correct
29 Correct 5 ms 4948 KB Output is correct
30 Correct 3 ms 4308 KB Output is correct
31 Correct 4 ms 4396 KB Output is correct
32 Correct 3 ms 4308 KB Output is correct
33 Correct 6 ms 5680 KB Output is correct
34 Correct 6 ms 5620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 2 ms 3796 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 3 ms 4052 KB Output is correct
12 Correct 2 ms 3796 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 3 ms 4068 KB Output is correct
15 Correct 3 ms 4052 KB Output is correct
16 Correct 2 ms 3924 KB Output is correct
17 Correct 5 ms 4180 KB Output is correct
18 Correct 2 ms 3924 KB Output is correct
19 Correct 3 ms 3924 KB Output is correct
20 Correct 3 ms 4052 KB Output is correct
21 Correct 2 ms 3924 KB Output is correct
22 Correct 2 ms 3924 KB Output is correct
23 Correct 3 ms 4052 KB Output is correct
24 Correct 3 ms 4180 KB Output is correct
25 Correct 3 ms 4180 KB Output is correct
26 Correct 2 ms 4052 KB Output is correct
27 Correct 2 ms 3924 KB Output is correct
28 Correct 3 ms 4308 KB Output is correct
29 Correct 4 ms 4948 KB Output is correct
30 Correct 3 ms 4308 KB Output is correct
31 Correct 3 ms 4436 KB Output is correct
32 Correct 3 ms 4308 KB Output is correct
33 Correct 6 ms 5652 KB Output is correct
34 Correct 6 ms 5620 KB Output is correct
35 Correct 19 ms 7508 KB Output is correct
36 Correct 4 ms 4564 KB Output is correct
37 Correct 22 ms 7904 KB Output is correct
38 Correct 26 ms 8788 KB Output is correct
39 Correct 26 ms 8608 KB Output is correct
40 Correct 24 ms 8660 KB Output is correct
41 Correct 25 ms 8720 KB Output is correct
42 Correct 7 ms 4384 KB Output is correct
43 Correct 6 ms 4436 KB Output is correct
44 Correct 7 ms 4448 KB Output is correct
45 Correct 30 ms 11852 KB Output is correct
46 Correct 31 ms 11756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 3 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 2 ms 3796 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 4 ms 4052 KB Output is correct
12 Correct 3 ms 3796 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 3 ms 4052 KB Output is correct
15 Correct 3 ms 4052 KB Output is correct
16 Correct 2 ms 3924 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 2 ms 3924 KB Output is correct
19 Correct 2 ms 3924 KB Output is correct
20 Correct 3 ms 4052 KB Output is correct
21 Correct 2 ms 3924 KB Output is correct
22 Correct 2 ms 3924 KB Output is correct
23 Correct 3 ms 4052 KB Output is correct
24 Correct 3 ms 4180 KB Output is correct
25 Correct 3 ms 4080 KB Output is correct
26 Correct 3 ms 4052 KB Output is correct
27 Correct 3 ms 3924 KB Output is correct
28 Correct 3 ms 4308 KB Output is correct
29 Correct 5 ms 4996 KB Output is correct
30 Correct 3 ms 4304 KB Output is correct
31 Correct 4 ms 4436 KB Output is correct
32 Correct 3 ms 4336 KB Output is correct
33 Correct 6 ms 5652 KB Output is correct
34 Correct 6 ms 5620 KB Output is correct
35 Correct 30 ms 7536 KB Output is correct
36 Correct 6 ms 4564 KB Output is correct
37 Correct 32 ms 7920 KB Output is correct
38 Correct 27 ms 8740 KB Output is correct
39 Correct 37 ms 8652 KB Output is correct
40 Correct 29 ms 8632 KB Output is correct
41 Correct 43 ms 8736 KB Output is correct
42 Correct 10 ms 4396 KB Output is correct
43 Correct 12 ms 4380 KB Output is correct
44 Correct 10 ms 4508 KB Output is correct
45 Correct 30 ms 11932 KB Output is correct
46 Correct 29 ms 11828 KB Output is correct
47 Correct 42 ms 16296 KB Output is correct
48 Correct 34 ms 8840 KB Output is correct
49 Correct 17 ms 7884 KB Output is correct
50 Correct 11 ms 7124 KB Output is correct
51 Correct 38 ms 11848 KB Output is correct
52 Correct 41 ms 12248 KB Output is correct
53 Correct 18 ms 8640 KB Output is correct
54 Correct 4 ms 4756 KB Output is correct
55 Correct 5 ms 5216 KB Output is correct
56 Correct 18 ms 8176 KB Output is correct
57 Correct 16 ms 13172 KB Output is correct
58 Correct 9 ms 5772 KB Output is correct
59 Correct 10 ms 5980 KB Output is correct
60 Correct 11 ms 6560 KB Output is correct
61 Correct 11 ms 6236 KB Output is correct
62 Correct 44 ms 12296 KB Output is correct
63 Correct 92 ms 33004 KB Output is correct
64 Correct 109 ms 42012 KB Output is correct
65 Correct 125 ms 55280 KB Output is correct
66 Correct 182 ms 84476 KB Output is correct
67 Correct 169 ms 83736 KB Output is correct