답안 #933342

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
933342 2024-02-25T14:18:20 Z Hanksburger Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
126 ms 69432 KB
#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > vec;
priority_queue<pair<int, int> > pq;
vector<pair<int, int> > adj[30005];
int dist[30005], final[30005];
vector<int> tmp;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, s, e;
    cin >> n >> m;
    for (int i=0; i<m; i++)
    {
        int a, b;
        cin >> a >> b;
        vec.push_back({{b, a%b}, a});
        if (i==0)
            s=a;
        if (i==1)
            e=a;
    }
    sort(vec.begin(), vec.end());
    for (int i=0; i<vec.size(); i++)
    {
        tmp.push_back(vec[i].second);
        if (i==vec.size()-1 || vec[i].first!=vec[i+1].first)
        {
            int a=vec[i].first.first, b=vec[i].first.second, ind=0;
            for (int j=b; j<n; j+=a)
            {
                while (ind<tmp.size() && tmp[ind]<=j)
                    ind++;
                if (ind==tmp.size())
                    break;
                adj[tmp[ind]].push_back({j, (tmp[ind]-j)/a});
            }
            ind=tmp.size()-1;
            for (int j=(n-b-1)/a*a+b; j>=0; j-=a)
            {
                while (ind>=0 && tmp[ind]>=j)
                    ind--;
                if (ind==-1)
                    break;
                adj[tmp[ind]].push_back({j, (j-tmp[ind])/a});
            }
            tmp.clear();
        }
    }
    for (int i=0; i<n; i++)
        dist[i]=1e9;
    dist[s]=0;
    pq.push({-dist[s], s});
    while (!pq.empty())
    {
        int u=pq.top().second;
        pq.pop();
        if (final[u])
            continue;
        final[u]=1;
        for (int i=0; i<adj[u].size(); i++)
        {
            int v=adj[u][i].first, w=adj[u][i].second;
            if (dist[u]+w<dist[v])
            {
                dist[v]=dist[u]+w;
                pq.push({-dist[v], v});
            }
        }
    }
    if (dist[e]==1e9)
        cout << -1;
    else
        cout << dist[e];
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:26:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i=0; i<vec.size(); i++)
      |                   ~^~~~~~~~~~~
skyscraper.cpp:29:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         if (i==vec.size()-1 || vec[i].first!=vec[i+1].first)
      |             ~^~~~~~~~~~~~~~
skyscraper.cpp:34:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |                 while (ind<tmp.size() && tmp[ind]<=j)
      |                        ~~~^~~~~~~~~~~
skyscraper.cpp:36:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |                 if (ind==tmp.size())
      |                     ~~~^~~~~~~~~~~~
skyscraper.cpp:63:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for (int i=0; i<adj[u].size(); i++)
      |                       ~^~~~~~~~~~~~~~
skyscraper.cpp:73:15: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
   73 |     if (dist[e]==1e9)
      |         ~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1172 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1112 KB Output is correct
11 Correct 1 ms 1112 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1112 KB Output is correct
3 Correct 1 ms 1112 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1180 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 2 ms 1372 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 2 ms 1368 KB Output is correct
21 Correct 1 ms 1112 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1112 KB Output is correct
24 Correct 2 ms 1372 KB Output is correct
25 Correct 2 ms 1372 KB Output is correct
26 Correct 1 ms 1112 KB Output is correct
27 Correct 1 ms 1116 KB Output is correct
28 Correct 2 ms 1368 KB Output is correct
29 Correct 3 ms 1884 KB Output is correct
30 Correct 2 ms 1372 KB Output is correct
31 Correct 2 ms 1628 KB Output is correct
32 Correct 2 ms 1336 KB Output is correct
33 Correct 4 ms 2396 KB Output is correct
34 Correct 4 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1368 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1164 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1056 KB Output is correct
17 Correct 1 ms 1372 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1268 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1172 KB Output is correct
23 Correct 1 ms 1112 KB Output is correct
24 Correct 2 ms 1372 KB Output is correct
25 Correct 1 ms 1372 KB Output is correct
26 Correct 1 ms 1116 KB Output is correct
27 Correct 1 ms 1116 KB Output is correct
28 Correct 1 ms 1440 KB Output is correct
29 Correct 3 ms 1880 KB Output is correct
30 Correct 1 ms 1448 KB Output is correct
31 Correct 2 ms 1628 KB Output is correct
32 Correct 1 ms 1372 KB Output is correct
33 Correct 4 ms 2460 KB Output is correct
34 Correct 4 ms 2396 KB Output is correct
35 Correct 10 ms 2644 KB Output is correct
36 Correct 2 ms 1372 KB Output is correct
37 Correct 8 ms 3672 KB Output is correct
38 Correct 10 ms 3416 KB Output is correct
39 Correct 10 ms 3416 KB Output is correct
40 Correct 10 ms 3416 KB Output is correct
41 Correct 10 ms 3404 KB Output is correct
42 Correct 5 ms 1880 KB Output is correct
43 Correct 5 ms 1948 KB Output is correct
44 Correct 5 ms 1880 KB Output is correct
45 Correct 13 ms 6232 KB Output is correct
46 Correct 14 ms 6232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1112 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1252 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1372 KB Output is correct
18 Correct 1 ms 1112 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 2 ms 1372 KB Output is correct
25 Correct 2 ms 1188 KB Output is correct
26 Correct 1 ms 1116 KB Output is correct
27 Correct 1 ms 1112 KB Output is correct
28 Correct 2 ms 1372 KB Output is correct
29 Correct 2 ms 1880 KB Output is correct
30 Correct 2 ms 1368 KB Output is correct
31 Correct 3 ms 1624 KB Output is correct
32 Correct 2 ms 1372 KB Output is correct
33 Correct 3 ms 2396 KB Output is correct
34 Correct 4 ms 2396 KB Output is correct
35 Correct 8 ms 2648 KB Output is correct
36 Correct 2 ms 1368 KB Output is correct
37 Correct 8 ms 3484 KB Output is correct
38 Correct 10 ms 3416 KB Output is correct
39 Correct 10 ms 3416 KB Output is correct
40 Correct 10 ms 3412 KB Output is correct
41 Correct 10 ms 3416 KB Output is correct
42 Correct 5 ms 1880 KB Output is correct
43 Correct 5 ms 1880 KB Output is correct
44 Correct 5 ms 1880 KB Output is correct
45 Correct 13 ms 6232 KB Output is correct
46 Correct 13 ms 6228 KB Output is correct
47 Correct 23 ms 10996 KB Output is correct
48 Correct 9 ms 4184 KB Output is correct
49 Correct 7 ms 3160 KB Output is correct
50 Correct 6 ms 3048 KB Output is correct
51 Correct 24 ms 5972 KB Output is correct
52 Correct 25 ms 6488 KB Output is correct
53 Correct 12 ms 3668 KB Output is correct
54 Correct 2 ms 1880 KB Output is correct
55 Correct 3 ms 2136 KB Output is correct
56 Correct 9 ms 2904 KB Output is correct
57 Correct 26 ms 10080 KB Output is correct
58 Correct 7 ms 2900 KB Output is correct
59 Correct 8 ms 3412 KB Output is correct
60 Correct 9 ms 3928 KB Output is correct
61 Correct 9 ms 3416 KB Output is correct
62 Correct 17 ms 6956 KB Output is correct
63 Correct 51 ms 24344 KB Output is correct
64 Correct 56 ms 32840 KB Output is correct
65 Correct 68 ms 42836 KB Output is correct
66 Correct 126 ms 69432 KB Output is correct
67 Correct 114 ms 69312 KB Output is correct