Submission #119139

# Submission time Handle Problem Language Result Execution time Memory
119139 2019-06-20T12:47:48 Z Charis02 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
819 ms 6512 KB
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 30004
#define INF 1e9+7

using namespace std;

ll pos[N],jump[N],n,m,d[N];
vector < vector < ll > > building(N);

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n >> m;

    rep(i,0,m)
    {
        cin >> pos[i] >> jump[i];

        building[pos[i]].push_back(jump[i]);
    }

    rep(i,0,n)
        d[i] = INF;

    priority_queue < pi > pq;
    pq.push(mp(0,pos[0]));
    d[pos[0]] = 0;

    while(!pq.empty())
    {
        pi cur = pq.top();
        pq.pop();

        if(-cur.first > d[cur.second])
            continue;

        rep(i,0,building[cur.second].size())
        {
            ll p = building[cur.second][i];

            ll j = -1;

            while(cur.second + p*j >= 0)
            {
                if(-cur.first - j < d[cur.second+p*j])
                {
                    d[cur.second+p*j] = -cur.first-j;
                    pq.push(mp(-d[cur.second+p*j],cur.second+p*j));
                }
                j--;
            }

            j = 0;

            while(cur.second + p*j < n)
            {
                if(-cur.first + j < d[cur.second+p*j])
                {
                    d[cur.second+p*j] = -cur.first+j;
                    pq.push(mp(-d[cur.second+p*j],cur.second+p*j));
                }
                j++;
            }
        }
    }

    if(d[pos[1]] != INF)
        cout << d[pos[1]] << endl;
    else
        cout << -1 << endl;
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:13:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,a,b) for(int i = a;i < b;i++)
skyscraper.cpp:50:13:
         rep(i,0,building[cur.second].size())
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:50:9: note: in expansion of macro 'rep'
         rep(i,0,building[cur.second].size())
         ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 2 ms 1024 KB Output is correct
3 Correct 2 ms 1152 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 3 ms 1024 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 3 ms 1140 KB Output is correct
4 Correct 3 ms 1024 KB Output is correct
5 Correct 2 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 3 ms 1024 KB Output is correct
9 Correct 2 ms 1024 KB Output is correct
10 Correct 2 ms 1152 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 3 ms 1152 KB Output is correct
13 Correct 3 ms 1152 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 2 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1024 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 6 ms 1152 KB Output is correct
7 Correct 3 ms 1024 KB Output is correct
8 Correct 3 ms 1024 KB Output is correct
9 Correct 6 ms 1152 KB Output is correct
10 Correct 2 ms 1152 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 4 ms 1152 KB Output is correct
13 Correct 3 ms 1152 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 3 ms 1152 KB Output is correct
18 Correct 3 ms 1152 KB Output is correct
19 Correct 3 ms 1152 KB Output is correct
20 Correct 6 ms 1280 KB Output is correct
21 Correct 3 ms 1152 KB Output is correct
22 Correct 3 ms 1152 KB Output is correct
23 Correct 3 ms 1152 KB Output is correct
24 Correct 4 ms 1280 KB Output is correct
25 Correct 4 ms 1280 KB Output is correct
26 Correct 6 ms 1152 KB Output is correct
27 Correct 6 ms 1152 KB Output is correct
28 Correct 3 ms 1280 KB Output is correct
29 Correct 5 ms 1280 KB Output is correct
30 Correct 4 ms 1280 KB Output is correct
31 Correct 4 ms 1408 KB Output is correct
32 Correct 3 ms 1280 KB Output is correct
33 Correct 4 ms 1436 KB Output is correct
34 Correct 5 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 2 ms 1024 KB Output is correct
4 Correct 9 ms 1024 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1024 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
9 Correct 3 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 3 ms 1252 KB Output is correct
13 Correct 3 ms 1152 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 3 ms 1280 KB Output is correct
18 Correct 3 ms 1152 KB Output is correct
19 Correct 2 ms 1152 KB Output is correct
20 Correct 6 ms 1280 KB Output is correct
21 Correct 3 ms 1152 KB Output is correct
22 Correct 3 ms 1152 KB Output is correct
23 Correct 3 ms 1152 KB Output is correct
24 Correct 4 ms 1280 KB Output is correct
25 Correct 4 ms 1280 KB Output is correct
26 Correct 6 ms 1152 KB Output is correct
27 Correct 6 ms 1152 KB Output is correct
28 Correct 3 ms 1408 KB Output is correct
29 Correct 4 ms 1280 KB Output is correct
30 Correct 3 ms 1280 KB Output is correct
31 Correct 3 ms 1280 KB Output is correct
32 Correct 4 ms 1280 KB Output is correct
33 Correct 4 ms 1408 KB Output is correct
34 Correct 5 ms 1536 KB Output is correct
35 Correct 10 ms 2304 KB Output is correct
36 Correct 4 ms 1280 KB Output is correct
37 Correct 9 ms 2048 KB Output is correct
38 Correct 11 ms 2432 KB Output is correct
39 Correct 12 ms 2432 KB Output is correct
40 Correct 12 ms 2432 KB Output is correct
41 Correct 11 ms 2432 KB Output is correct
42 Correct 61 ms 2176 KB Output is correct
43 Correct 56 ms 2176 KB Output is correct
44 Correct 59 ms 2084 KB Output is correct
45 Correct 10 ms 2304 KB Output is correct
46 Correct 10 ms 2432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1024 KB Output is correct
5 Correct 3 ms 1024 KB Output is correct
6 Correct 2 ms 1024 KB Output is correct
7 Correct 3 ms 1024 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
9 Correct 3 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 3 ms 1280 KB Output is correct
13 Correct 3 ms 1152 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
16 Correct 5 ms 1152 KB Output is correct
17 Correct 4 ms 1280 KB Output is correct
18 Correct 3 ms 1152 KB Output is correct
19 Correct 3 ms 1152 KB Output is correct
20 Correct 7 ms 1280 KB Output is correct
21 Correct 3 ms 1152 KB Output is correct
22 Correct 3 ms 1152 KB Output is correct
23 Correct 3 ms 1152 KB Output is correct
24 Correct 4 ms 1280 KB Output is correct
25 Correct 4 ms 1280 KB Output is correct
26 Correct 7 ms 1152 KB Output is correct
27 Correct 6 ms 1152 KB Output is correct
28 Correct 4 ms 1152 KB Output is correct
29 Correct 4 ms 1408 KB Output is correct
30 Correct 4 ms 1280 KB Output is correct
31 Correct 4 ms 1280 KB Output is correct
32 Correct 4 ms 1280 KB Output is correct
33 Correct 4 ms 1408 KB Output is correct
34 Correct 5 ms 1536 KB Output is correct
35 Correct 9 ms 2176 KB Output is correct
36 Correct 5 ms 1408 KB Output is correct
37 Correct 9 ms 2048 KB Output is correct
38 Correct 12 ms 2432 KB Output is correct
39 Correct 12 ms 2432 KB Output is correct
40 Correct 12 ms 2432 KB Output is correct
41 Correct 17 ms 2432 KB Output is correct
42 Correct 59 ms 2048 KB Output is correct
43 Correct 57 ms 2176 KB Output is correct
44 Correct 61 ms 2212 KB Output is correct
45 Correct 11 ms 2304 KB Output is correct
46 Correct 10 ms 2304 KB Output is correct
47 Correct 22 ms 3324 KB Output is correct
48 Correct 11 ms 2304 KB Output is correct
49 Correct 12 ms 2304 KB Output is correct
50 Correct 7 ms 2048 KB Output is correct
51 Correct 35 ms 4984 KB Output is correct
52 Correct 35 ms 3964 KB Output is correct
53 Correct 19 ms 3836 KB Output is correct
54 Correct 4 ms 1664 KB Output is correct
55 Correct 11 ms 1664 KB Output is correct
56 Correct 737 ms 3572 KB Output is correct
57 Correct 56 ms 5744 KB Output is correct
58 Correct 507 ms 2520 KB Output is correct
59 Correct 819 ms 2688 KB Output is correct
60 Correct 577 ms 2676 KB Output is correct
61 Correct 683 ms 2688 KB Output is correct
62 Correct 16 ms 3072 KB Output is correct
63 Correct 32 ms 4596 KB Output is correct
64 Correct 31 ms 4600 KB Output is correct
65 Correct 36 ms 4732 KB Output is correct
66 Correct 48 ms 6512 KB Output is correct
67 Correct 44 ms 6512 KB Output is correct