Submission #42138

# Submission time Handle Problem Language Result Execution time Memory
42138 2018-02-22T18:59:42 Z XmtosX Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
2 ms 1256 KB
#include <bits/stdc++.h>
using namespace std;
short int n,p[30004],b[30004],m;
priority_queue <pair<short int,short int> ,vector <pair<short int,short int> >,greater <pair<short int,short int> > > pq;
bool vis[30004];
vector <int> v[30004];
short int cur[30004];
void dij()
{
    for (int i=0;i<n;i++)
        cur[i]=32000;
    cur[b[0]]=0;
    pq.push({0,b[0]});
    while (!pq.empty())
    {
        int x= (pq.top()).second;
        int y= (pq.top()).first;
        pq.pop();
        if (vis[x])
            continue;
        vis[x]=true;
        if (x==b[1])
            return;
        for (short int i=0;i<v[x].size();i++)
        {
            for (short int j=1;j*v[x][i]+x<n;j++)
            {
                short int a= (j*v[x][i]+x);
                if (cur[a]>y+j)
                {
                    cur[a]=y+j;
                    pq.push({cur[a],a});
                }
                a= (x-j*v[x][i]);
                if (a>=0)
                {
                    if (cur[a]>y+j)
                    {
                        cur[a]=y+j;
                        pq.push({cur[a],a});
                    }
                }
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >>n>>m;
    for (int i=0;i<m;i++)
    {
        cin >>b[i]>>p[i];
        v[b[i]].push_back(p[i]);
    }
    dij();
    if (!vis[b[1]])
        cout <<-1;
    else
        cout <<cur[b[1]];
    return 0;
}

Compilation message

skyscraper.cpp: In function 'void dij()':
skyscraper.cpp:24:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (short int i=0;i<v[x].size();i++)
                             ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1256 KB Output isn't correct
2 Halted 0 ms 0 KB -