Submission #450430

# Submission time Handle Problem Language Result Execution time Memory
450430 2021-08-02T21:18:29 Z soba Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
287 ms 64276 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 30001;
int dist[N];
vector<pair<int,int> >v[N];
int b[N] , p[N] ;
vector<pair<int,int> >vp;
int n , m ;
map<pair<int,int> , int>mp;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x , y;
    cin>> n>> m ;
    set<pair<int,int> >s;
    for(int i = 0 ; i < m ; i++)
    {
        cin >> b[i] >> p[i];
        if(i==0)x=b[i];
        if(i==1)y=b[i];
        s.insert({b[i], p[i]});
    }
    if(x==y)
    {
        cout << 0 ;
        return 0;
    }
    for(auto u : s)
    {
        int c=1;
        for(int j = u.first+u.second ; j< n ; j+= u.second)
        {
            v[u.first].push_back({j , c});
            c++;
            if(s.find({j,u.second})!=s.end())
                break;
        }
    }
    for(auto u : s)
    {
        int c=1;
        for(int j = u.first-u.second ; j>=0 ; j-= u.second)
        {
            v[u.first].push_back({j , c});
            c++;
            if(s.find({j,u.second})!=s.end())
                break;
        }
    }
    priority_queue<pair<int,int> >q;
    for (int i = 0; i <= n; i++) dist[i] = 1e9;
    dist[x] = 0;
    q.push({0,x});
    while (!q.empty())
    {
        int a = q.top().second;
        int ot= q.top().first;
        q.pop();
        if(a==y)
        {
            cout << 0-ot;
            return 0;
        }
        if( 0-ot >dist[a] )continue;
        //cout << a << " : " ;
        for (auto u : v[a])
        {
            int b = u.first, w = u.second;

          //  cout << b << " ";
            if (dist[a]+w < dist[b])
            {
                dist[b] = dist[a]+w;
                q.push({-dist[b],b});
            }
        }
        //cout << "\n";
    }
    cout << -1;

    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:26:5: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |     if(x==y)
      |     ^~
skyscraper.cpp:26:5: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1060 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 2 ms 1100 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 2 ms 1100 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 1100 KB Output is correct
16 Correct 2 ms 1100 KB Output is correct
17 Correct 3 ms 1228 KB Output is correct
18 Correct 2 ms 1100 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 3 ms 1100 KB Output is correct
21 Correct 1 ms 1100 KB Output is correct
22 Correct 2 ms 1100 KB Output is correct
23 Correct 2 ms 1100 KB Output is correct
24 Correct 3 ms 1228 KB Output is correct
25 Correct 3 ms 1228 KB Output is correct
26 Correct 2 ms 1100 KB Output is correct
27 Correct 2 ms 1100 KB Output is correct
28 Correct 4 ms 1328 KB Output is correct
29 Correct 4 ms 1740 KB Output is correct
30 Correct 2 ms 1228 KB Output is correct
31 Correct 3 ms 1484 KB Output is correct
32 Correct 2 ms 1356 KB Output is correct
33 Correct 6 ms 2380 KB Output is correct
34 Correct 6 ms 2380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 2 ms 1100 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 1100 KB Output is correct
16 Correct 2 ms 1100 KB Output is correct
17 Correct 3 ms 1228 KB Output is correct
18 Correct 2 ms 1100 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 2 ms 1100 KB Output is correct
21 Correct 1 ms 1100 KB Output is correct
22 Correct 2 ms 1100 KB Output is correct
23 Correct 2 ms 1100 KB Output is correct
24 Correct 3 ms 1228 KB Output is correct
25 Correct 3 ms 1228 KB Output is correct
26 Correct 2 ms 1100 KB Output is correct
27 Correct 2 ms 1100 KB Output is correct
28 Correct 4 ms 1356 KB Output is correct
29 Correct 4 ms 1740 KB Output is correct
30 Correct 2 ms 1356 KB Output is correct
31 Correct 3 ms 1484 KB Output is correct
32 Correct 2 ms 1356 KB Output is correct
33 Correct 6 ms 2404 KB Output is correct
34 Correct 6 ms 2380 KB Output is correct
35 Correct 31 ms 3396 KB Output is correct
36 Correct 5 ms 1484 KB Output is correct
37 Correct 42 ms 4164 KB Output is correct
38 Correct 47 ms 4456 KB Output is correct
39 Correct 47 ms 4380 KB Output is correct
40 Correct 47 ms 4396 KB Output is correct
41 Correct 49 ms 4352 KB Output is correct
42 Correct 7 ms 1356 KB Output is correct
43 Correct 7 ms 1356 KB Output is correct
44 Correct 7 ms 1356 KB Output is correct
45 Correct 36 ms 6904 KB Output is correct
46 Correct 35 ms 6908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 2 ms 1100 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 1100 KB Output is correct
16 Correct 2 ms 1100 KB Output is correct
17 Correct 3 ms 1228 KB Output is correct
18 Correct 2 ms 1100 KB Output is correct
19 Correct 1 ms 1104 KB Output is correct
20 Correct 2 ms 1104 KB Output is correct
21 Correct 1 ms 1100 KB Output is correct
22 Correct 2 ms 1100 KB Output is correct
23 Correct 2 ms 1100 KB Output is correct
24 Correct 3 ms 1228 KB Output is correct
25 Correct 2 ms 1228 KB Output is correct
26 Correct 2 ms 1100 KB Output is correct
27 Correct 2 ms 1100 KB Output is correct
28 Correct 4 ms 1356 KB Output is correct
29 Correct 4 ms 1740 KB Output is correct
30 Correct 2 ms 1236 KB Output is correct
31 Correct 3 ms 1484 KB Output is correct
32 Correct 2 ms 1364 KB Output is correct
33 Correct 6 ms 2380 KB Output is correct
34 Correct 6 ms 2416 KB Output is correct
35 Correct 33 ms 3512 KB Output is correct
36 Correct 5 ms 1356 KB Output is correct
37 Correct 44 ms 4204 KB Output is correct
38 Correct 47 ms 4420 KB Output is correct
39 Correct 47 ms 4424 KB Output is correct
40 Correct 47 ms 4328 KB Output is correct
41 Correct 47 ms 4364 KB Output is correct
42 Correct 7 ms 1356 KB Output is correct
43 Correct 7 ms 1356 KB Output is correct
44 Correct 7 ms 1356 KB Output is correct
45 Correct 36 ms 6960 KB Output is correct
46 Correct 35 ms 6988 KB Output is correct
47 Correct 158 ms 11400 KB Output is correct
48 Correct 52 ms 4672 KB Output is correct
49 Correct 45 ms 3644 KB Output is correct
50 Correct 28 ms 3348 KB Output is correct
51 Correct 76 ms 6604 KB Output is correct
52 Correct 83 ms 7148 KB Output is correct
53 Correct 27 ms 3732 KB Output is correct
54 Correct 3 ms 1612 KB Output is correct
55 Correct 4 ms 1992 KB Output is correct
56 Correct 22 ms 3612 KB Output is correct
57 Correct 46 ms 10112 KB Output is correct
58 Correct 10 ms 2496 KB Output is correct
59 Correct 11 ms 2844 KB Output is correct
60 Correct 14 ms 3460 KB Output is correct
61 Correct 15 ms 2820 KB Output is correct
62 Correct 93 ms 8052 KB Output is correct
63 Correct 103 ms 24272 KB Output is correct
64 Correct 115 ms 27500 KB Output is correct
65 Correct 152 ms 37256 KB Output is correct
66 Correct 287 ms 64236 KB Output is correct
67 Correct 251 ms 64276 KB Output is correct