Submission #164912

# Submission time Handle Problem Language Result Execution time Memory
164912 2019-11-24T05:48:10 Z combi1k1 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
497 ms 121000 KB
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native"

#include<bits/stdc++.h>

using namespace std;

#define X   first
#define Y   second

#define pb  push_back

const int   N   = 1e6 + 1;

typedef pair<int,int>   ii;

vector<ii>  g[N];

int d[N];

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;  cin >> n;
    int m;  cin >> m;

    int s, t;

    vector<ii>  doge;

    for(int i = 0 ; i < m ; ++i)    {
        int b;  cin >> b;
        int p;  cin >> p;

        assert(p > 0);

        if (p < 30) {
            g[b].pb(ii(p * n + b,0));
            doge.pb(ii(p,b % p));
        }
        else    {
            for(int j = b - p ; j >= 0 ; j -= p)    g[b].pb(ii(j,(b - j) / p));
            for(int j = b + p ; j <  n ; j += p)    g[b].pb(ii(j,(j - b) / p));
        }

        if (i == 0) s = b;
        if (i == 1) t = b;
    }
    sort(doge.begin(),doge.end());
    doge.erase(unique(doge.begin(),doge.end()),doge.end());

    for(ii  a : doge)   {
        int b = a.Y;
        int p = a.X;
        for(int i = b ; i < n ; i += p) {
            int u = p * n + i;
            int v = p * n + i + p;
            if (v < p * n + n)
                g[u].pb(ii(v,1)),
                g[v].pb(ii(u,1));

            g[u].pb(ii(i,0));
        }
    }
    for(int i = 0 ; i < 30 ; ++i)
    for(int j = 0 ; j < n ; ++j)
        d[i * n + j] = 1e9 + 7;

    d[s] = 0;

    priority_queue<ii,vector<ii>,greater<ii> >  pq;

    pq.push(ii(0,s));

    while (pq.size())   {
        int du = pq.top().X;
        int  u = pq.top().Y;

        pq.pop();

        if (du != d[u])
            continue;

        for(ii  e : g[u])   {
            int v = e.X;
            int w = e.Y;
            if (d[v] > du + w)    {
                d[v] = du + w;
                pq.push(ii(d[v],v));
            }
        }
    }

    cout << (d[t] < 1e9 + 7 ? d[t] : -1) << endl;
}

Compilation message

skyscraper.cpp:1:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/stack:200000000")
 
skyscraper.cpp:3:20: warning: '#pragma GCC target (string [,string]...)' does not have a final ')' [-Wpragmas]
 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native"
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:96:17: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
     cout << (d[t] < 1e9 + 7 ? d[t] : -1) << endl;
              ~~~^
# Verdict Execution time Memory Grader output
1 Correct 26 ms 23800 KB Output is correct
2 Correct 26 ms 23800 KB Output is correct
3 Correct 26 ms 23800 KB Output is correct
4 Correct 27 ms 23800 KB Output is correct
5 Correct 26 ms 23800 KB Output is correct
6 Correct 26 ms 23800 KB Output is correct
7 Correct 26 ms 23816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 23876 KB Output is correct
2 Correct 27 ms 23800 KB Output is correct
3 Correct 26 ms 23800 KB Output is correct
4 Correct 27 ms 23772 KB Output is correct
5 Correct 27 ms 23800 KB Output is correct
6 Correct 26 ms 23800 KB Output is correct
7 Correct 26 ms 23800 KB Output is correct
8 Correct 26 ms 23800 KB Output is correct
9 Correct 27 ms 23928 KB Output is correct
10 Correct 27 ms 23928 KB Output is correct
11 Correct 28 ms 24056 KB Output is correct
12 Correct 28 ms 23928 KB Output is correct
13 Correct 27 ms 23928 KB Output is correct
14 Correct 32 ms 24056 KB Output is correct
15 Correct 29 ms 24056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 23800 KB Output is correct
2 Correct 27 ms 23800 KB Output is correct
3 Correct 27 ms 23800 KB Output is correct
4 Correct 27 ms 23800 KB Output is correct
5 Correct 27 ms 23800 KB Output is correct
6 Correct 28 ms 23928 KB Output is correct
7 Correct 30 ms 23800 KB Output is correct
8 Correct 27 ms 23800 KB Output is correct
9 Correct 27 ms 23800 KB Output is correct
10 Correct 28 ms 23928 KB Output is correct
11 Correct 29 ms 24060 KB Output is correct
12 Correct 27 ms 23928 KB Output is correct
13 Correct 28 ms 23928 KB Output is correct
14 Correct 29 ms 24056 KB Output is correct
15 Correct 28 ms 23992 KB Output is correct
16 Correct 28 ms 23928 KB Output is correct
17 Correct 31 ms 24312 KB Output is correct
18 Correct 29 ms 24184 KB Output is correct
19 Correct 28 ms 24184 KB Output is correct
20 Correct 28 ms 24184 KB Output is correct
21 Correct 28 ms 23928 KB Output is correct
22 Correct 28 ms 24184 KB Output is correct
23 Correct 28 ms 24184 KB Output is correct
24 Correct 30 ms 24440 KB Output is correct
25 Correct 29 ms 24312 KB Output is correct
26 Correct 28 ms 24440 KB Output is correct
27 Correct 29 ms 24440 KB Output is correct
28 Correct 30 ms 24716 KB Output is correct
29 Correct 42 ms 26360 KB Output is correct
30 Correct 31 ms 24824 KB Output is correct
31 Correct 29 ms 24568 KB Output is correct
32 Correct 30 ms 24412 KB Output is correct
33 Correct 47 ms 27384 KB Output is correct
34 Correct 48 ms 27384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 23800 KB Output is correct
2 Correct 27 ms 23800 KB Output is correct
3 Correct 27 ms 23800 KB Output is correct
4 Correct 27 ms 23928 KB Output is correct
5 Correct 27 ms 23800 KB Output is correct
6 Correct 28 ms 23928 KB Output is correct
7 Correct 27 ms 23800 KB Output is correct
8 Correct 27 ms 23800 KB Output is correct
9 Correct 27 ms 23928 KB Output is correct
10 Correct 28 ms 23928 KB Output is correct
11 Correct 28 ms 23928 KB Output is correct
12 Correct 28 ms 23928 KB Output is correct
13 Correct 28 ms 23936 KB Output is correct
14 Correct 28 ms 23928 KB Output is correct
15 Correct 28 ms 23928 KB Output is correct
16 Correct 28 ms 23928 KB Output is correct
17 Correct 30 ms 24312 KB Output is correct
18 Correct 28 ms 24192 KB Output is correct
19 Correct 29 ms 24184 KB Output is correct
20 Correct 32 ms 24300 KB Output is correct
21 Correct 28 ms 23932 KB Output is correct
22 Correct 28 ms 24184 KB Output is correct
23 Correct 29 ms 24184 KB Output is correct
24 Correct 30 ms 24312 KB Output is correct
25 Correct 29 ms 24312 KB Output is correct
26 Correct 29 ms 24440 KB Output is correct
27 Correct 29 ms 24440 KB Output is correct
28 Correct 32 ms 24696 KB Output is correct
29 Correct 42 ms 26360 KB Output is correct
30 Correct 32 ms 24952 KB Output is correct
31 Correct 29 ms 24568 KB Output is correct
32 Correct 28 ms 24440 KB Output is correct
33 Correct 46 ms 27384 KB Output is correct
34 Correct 48 ms 27384 KB Output is correct
35 Correct 44 ms 26104 KB Output is correct
36 Correct 31 ms 24488 KB Output is correct
37 Correct 56 ms 27768 KB Output is correct
38 Correct 55 ms 27420 KB Output is correct
39 Correct 54 ms 27340 KB Output is correct
40 Correct 54 ms 27356 KB Output is correct
41 Correct 53 ms 27272 KB Output is correct
42 Correct 36 ms 25076 KB Output is correct
43 Correct 39 ms 25072 KB Output is correct
44 Correct 35 ms 24920 KB Output is correct
45 Correct 71 ms 30720 KB Output is correct
46 Correct 61 ms 30712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 23800 KB Output is correct
2 Correct 27 ms 23800 KB Output is correct
3 Correct 27 ms 23800 KB Output is correct
4 Correct 27 ms 23800 KB Output is correct
5 Correct 27 ms 23800 KB Output is correct
6 Correct 27 ms 23800 KB Output is correct
7 Correct 27 ms 23800 KB Output is correct
8 Correct 28 ms 23772 KB Output is correct
9 Correct 28 ms 23800 KB Output is correct
10 Correct 29 ms 23900 KB Output is correct
11 Correct 28 ms 23928 KB Output is correct
12 Correct 27 ms 23928 KB Output is correct
13 Correct 27 ms 23928 KB Output is correct
14 Correct 29 ms 24056 KB Output is correct
15 Correct 28 ms 24056 KB Output is correct
16 Correct 28 ms 23928 KB Output is correct
17 Correct 31 ms 24312 KB Output is correct
18 Correct 28 ms 24184 KB Output is correct
19 Correct 29 ms 24184 KB Output is correct
20 Correct 29 ms 24312 KB Output is correct
21 Correct 28 ms 23928 KB Output is correct
22 Correct 29 ms 24160 KB Output is correct
23 Correct 29 ms 24184 KB Output is correct
24 Correct 30 ms 24312 KB Output is correct
25 Correct 29 ms 24312 KB Output is correct
26 Correct 30 ms 24440 KB Output is correct
27 Correct 29 ms 24440 KB Output is correct
28 Correct 31 ms 24696 KB Output is correct
29 Correct 42 ms 26360 KB Output is correct
30 Correct 33 ms 24952 KB Output is correct
31 Correct 30 ms 24568 KB Output is correct
32 Correct 29 ms 24440 KB Output is correct
33 Correct 48 ms 27384 KB Output is correct
34 Correct 47 ms 27260 KB Output is correct
35 Correct 46 ms 26108 KB Output is correct
36 Correct 31 ms 24416 KB Output is correct
37 Correct 56 ms 27768 KB Output is correct
38 Correct 53 ms 27504 KB Output is correct
39 Correct 56 ms 27384 KB Output is correct
40 Correct 53 ms 27384 KB Output is correct
41 Correct 54 ms 27256 KB Output is correct
42 Correct 36 ms 25076 KB Output is correct
43 Correct 35 ms 25076 KB Output is correct
44 Correct 35 ms 24920 KB Output is correct
45 Correct 88 ms 30712 KB Output is correct
46 Correct 59 ms 30840 KB Output is correct
47 Correct 162 ms 41592 KB Output is correct
48 Correct 58 ms 32636 KB Output is correct
49 Correct 46 ms 29432 KB Output is correct
50 Correct 47 ms 30584 KB Output is correct
51 Correct 108 ms 35576 KB Output is correct
52 Correct 116 ms 36472 KB Output is correct
53 Correct 50 ms 30440 KB Output is correct
54 Correct 36 ms 28792 KB Output is correct
55 Correct 40 ms 29944 KB Output is correct
56 Correct 49 ms 30196 KB Output is correct
57 Correct 219 ms 48244 KB Output is correct
58 Correct 49 ms 30960 KB Output is correct
59 Correct 58 ms 32244 KB Output is correct
60 Correct 59 ms 32844 KB Output is correct
61 Correct 56 ms 31892 KB Output is correct
62 Correct 90 ms 39220 KB Output is correct
63 Correct 130 ms 51820 KB Output is correct
64 Correct 142 ms 60376 KB Output is correct
65 Correct 205 ms 65736 KB Output is correct
66 Correct 497 ms 121000 KB Output is correct
67 Correct 493 ms 120676 KB Output is correct