제출 #411713

#제출 시각아이디문제언어결과실행 시간메모리
411713MasterTasterJakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
403 ms262148 KiB
#include <bits/stdc++.h>

#define pb push_back
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define INF 1000000000000010LL
#define MAXN 30010

using namespace std;

ll d[MAXN];
int n, m;
vector<int> g[MAXN];
vector<ll> w[MAXN];

void dijkstra(int s)
{
    for (int i=0; i<n; i++) d[i]=INF;
    d[s]=0;

    priority_queue< pair<int, ll>, vector< pair<int, ll> >, greater< pair<int, ll> > > q;
    q.push({0, s});

    while (!q.empty())
    {
        int u=q.top().second;
        ll du=q.top().first;
        q.pop();

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

        for (int i=0; i<g[u].size(); i++)
        {
            int v=g[u][i];
            if (d[u]+w[u][i]<d[v])
            {
                d[v]=d[u]+w[u][i];
                q.push({d[v], v});
            }
        }
    }
}

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

    cin>>n>>m;

    int poc, kraj;
    for (int i=0; i<m; i++)
    {
        int u; cin>>u;
        int p; cin>>p;

        if (i==0) poc=u;
        if (i==1) kraj=u;

        for (int j=1; u-j*p>=0; j++) { g[u].pb(u-j*p); w[u].pb(j); }
        for (int j=1; u+j*p<n; j++) { g[u].pb(u+j*p); w[u].pb(j); }
    }

    dijkstra(poc);
    if (d[kraj]==INF) cout<<-1;
    else cout<<d[kraj];
}

컴파일 시 표준 에러 (stderr) 메시지

skyscraper.cpp: In function 'void dijkstra(int)':
skyscraper.cpp:34:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for (int i=0; i<g[u].size(); i++)
      |                       ~^~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:65:15: warning: 'kraj' may be used uninitialized in this function [-Wmaybe-uninitialized]
   65 |     if (d[kraj]==INF) cout<<-1;
      |         ~~~~~~^
skyscraper.cpp:64:13: warning: 'poc' may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |     dijkstra(poc);
      |     ~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...