Submission #308901

# Submission time Handle Problem Language Result Execution time Memory
308901 2020-10-02T07:56:40 Z jainbot27 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
931 ms 4084 KB
#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()

#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, z, y) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, 0, z)
#define trav(x, y) for(auto&x:y)

using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;

template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const char nl = '\n';
const int mxN = 3e4 + 10;
const int MOD = 1e9 + 7;
const long long infLL = 1e18;

int n, m, pos[mxN], dist[mxN], len[mxN]; vi nodes[mxN]; bool done[mxN];
priority_queue<pii, vpii, greater<pii>> pq;
int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    memset(len, 0x3f, sizeof(len));
    F0R(i, m){
        cin >> pos[i] >> dist[i];
        nodes[pos[i]].pb(dist[i]);
    }
    int F = pos[0], S = pos[1];
    len[pos[0]] = 0;
    pq.push({0, pos[0]});
    while(!pq.empty()){
        pii x = pq.top(); pq.pop();
        // cout << x.f << " " << x.s << endl;
        if(x.f!=len[x.s]) continue;
        trav(speed, nodes[x.s]){
            int p = x.s + speed;
            for(int i = 1; p < n; i++, p+=speed){
                if(ckmin(len[p], x.f+i)){
                    pq.push({len[p], p});
                } 
            }
            p = x.s - speed;
            for(int i = 1; p >= 0; i++, p-=speed){
                if(ckmin(len[p], x.f+i)){
                    pq.push({len[p], p});
                } 
            }
        }
    }
    cout << (len[S]>=MOD?-1:len[S]) << nl;
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:42:9: warning: unused variable 'F' [-Wunused-variable]
   42 |     int F = pos[0], S = pos[1];
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 1 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 1 ms 1152 KB Output is correct
8 Correct 1 ms 1152 KB Output is correct
9 Correct 1 ms 1152 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 1 ms 1280 KB Output is correct
12 Correct 2 ms 1152 KB Output is correct
13 Correct 2 ms 1152 KB Output is correct
14 Correct 1 ms 1280 KB Output is correct
15 Correct 2 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 1 ms 1152 KB Output is correct
8 Correct 1 ms 1152 KB Output is correct
9 Correct 1 ms 1152 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 2 ms 1280 KB Output is correct
12 Correct 2 ms 1280 KB Output is correct
13 Correct 2 ms 1152 KB Output is correct
14 Correct 2 ms 1280 KB Output is correct
15 Correct 2 ms 1280 KB Output is correct
16 Correct 1 ms 1152 KB Output is correct
17 Correct 2 ms 1280 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
19 Correct 1 ms 1152 KB Output is correct
20 Correct 6 ms 1280 KB Output is correct
21 Correct 2 ms 1152 KB Output is correct
22 Correct 2 ms 1152 KB Output is correct
23 Correct 2 ms 1280 KB Output is correct
24 Correct 2 ms 1280 KB Output is correct
25 Correct 3 ms 1280 KB Output is correct
26 Correct 7 ms 1280 KB Output is correct
27 Correct 5 ms 1280 KB Output is correct
28 Correct 2 ms 1280 KB Output is correct
29 Correct 3 ms 1408 KB Output is correct
30 Correct 2 ms 1280 KB Output is correct
31 Correct 2 ms 1280 KB Output is correct
32 Correct 2 ms 1280 KB Output is correct
33 Correct 3 ms 1408 KB Output is correct
34 Correct 4 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 1 ms 1152 KB Output is correct
8 Correct 1 ms 1152 KB Output is correct
9 Correct 1 ms 1152 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 2 ms 1152 KB Output is correct
12 Correct 2 ms 1152 KB Output is correct
13 Correct 2 ms 1280 KB Output is correct
14 Correct 1 ms 1280 KB Output is correct
15 Correct 1 ms 1280 KB Output is correct
16 Correct 1 ms 1152 KB Output is correct
17 Correct 2 ms 1280 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
19 Correct 1 ms 1152 KB Output is correct
20 Correct 6 ms 1280 KB Output is correct
21 Correct 1 ms 1152 KB Output is correct
22 Correct 1 ms 1152 KB Output is correct
23 Correct 2 ms 1280 KB Output is correct
24 Correct 2 ms 1280 KB Output is correct
25 Correct 2 ms 1280 KB Output is correct
26 Correct 5 ms 1280 KB Output is correct
27 Correct 5 ms 1280 KB Output is correct
28 Correct 2 ms 1280 KB Output is correct
29 Correct 3 ms 1408 KB Output is correct
30 Correct 2 ms 1280 KB Output is correct
31 Correct 2 ms 1280 KB Output is correct
32 Correct 2 ms 1280 KB Output is correct
33 Correct 4 ms 1408 KB Output is correct
34 Correct 3 ms 1408 KB Output is correct
35 Correct 8 ms 1920 KB Output is correct
36 Correct 3 ms 1280 KB Output is correct
37 Correct 7 ms 1792 KB Output is correct
38 Correct 9 ms 2048 KB Output is correct
39 Correct 10 ms 2048 KB Output is correct
40 Correct 10 ms 2056 KB Output is correct
41 Correct 9 ms 2048 KB Output is correct
42 Correct 68 ms 1912 KB Output is correct
43 Correct 67 ms 1792 KB Output is correct
44 Correct 70 ms 1900 KB Output is correct
45 Correct 8 ms 2048 KB Output is correct
46 Correct 9 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 1 ms 1152 KB Output is correct
8 Correct 1 ms 1152 KB Output is correct
9 Correct 1 ms 1152 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 2 ms 1280 KB Output is correct
12 Correct 2 ms 1152 KB Output is correct
13 Correct 2 ms 1280 KB Output is correct
14 Correct 1 ms 1280 KB Output is correct
15 Correct 2 ms 1280 KB Output is correct
16 Correct 2 ms 1280 KB Output is correct
17 Correct 2 ms 1280 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
19 Correct 1 ms 1152 KB Output is correct
20 Correct 6 ms 1280 KB Output is correct
21 Correct 1 ms 1152 KB Output is correct
22 Correct 2 ms 1152 KB Output is correct
23 Correct 2 ms 1280 KB Output is correct
24 Correct 2 ms 1280 KB Output is correct
25 Correct 2 ms 1280 KB Output is correct
26 Correct 6 ms 1280 KB Output is correct
27 Correct 5 ms 1280 KB Output is correct
28 Correct 2 ms 1280 KB Output is correct
29 Correct 3 ms 1408 KB Output is correct
30 Correct 2 ms 1280 KB Output is correct
31 Correct 2 ms 1280 KB Output is correct
32 Correct 2 ms 1280 KB Output is correct
33 Correct 3 ms 1408 KB Output is correct
34 Correct 4 ms 1408 KB Output is correct
35 Correct 9 ms 1920 KB Output is correct
36 Correct 3 ms 1280 KB Output is correct
37 Correct 7 ms 1792 KB Output is correct
38 Correct 10 ms 2048 KB Output is correct
39 Correct 10 ms 2048 KB Output is correct
40 Correct 9 ms 2048 KB Output is correct
41 Correct 9 ms 2048 KB Output is correct
42 Correct 68 ms 1792 KB Output is correct
43 Correct 67 ms 1904 KB Output is correct
44 Correct 69 ms 1912 KB Output is correct
45 Correct 10 ms 2080 KB Output is correct
46 Correct 9 ms 2048 KB Output is correct
47 Correct 19 ms 2556 KB Output is correct
48 Correct 7 ms 2048 KB Output is correct
49 Correct 8 ms 2048 KB Output is correct
50 Correct 6 ms 1792 KB Output is correct
51 Correct 31 ms 3448 KB Output is correct
52 Correct 28 ms 2940 KB Output is correct
53 Correct 16 ms 2940 KB Output is correct
54 Correct 3 ms 1408 KB Output is correct
55 Correct 3 ms 1408 KB Output is correct
56 Correct 919 ms 2944 KB Output is correct
57 Correct 51 ms 3440 KB Output is correct
58 Correct 871 ms 1932 KB Output is correct
59 Correct 931 ms 2064 KB Output is correct
60 Correct 869 ms 2100 KB Output is correct
61 Correct 834 ms 2080 KB Output is correct
62 Correct 14 ms 2816 KB Output is correct
63 Correct 35 ms 3064 KB Output is correct
64 Correct 37 ms 4084 KB Output is correct
65 Correct 44 ms 4084 KB Output is correct
66 Correct 61 ms 3956 KB Output is correct
67 Correct 62 ms 3956 KB Output is correct