Submission #76827

# Submission time Handle Problem Language Result Execution time Memory
76827 2018-09-18T13:26:25 Z vex Jakarta Skyscrapers (APIO15_skyscraper) C++14
10 / 100
3 ms 1344 KB
#include <bits/stdc++.h>
#define maxn 30005
#define pii pair<int,int>
using namespace std;

int n,m;
vector<int>p[maxn];
priority_queue<pii>pq;
int dis[maxn];
bool bio[maxn];

bool cmp(int x,int y)
{
    return x>y;
}

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

    cin>>n>>m;
    int s;
    int e;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        p[x].push_back(y);
        if(i==0)s=x;
        if(i==1)e=x;
    }

    for(int i=0;i<n;i++)sort(p[i].begin(),p[i].end(),cmp);

    if(e==s)
    {
        cout<<"0"<<endl;
        return 0;
    }

    for(int i=0;i<n;i++)
    {
        dis[i]=maxn*maxn+55;
        bio[i]=false;
    }
    pq.push({0,s});
    dis[s]=0;

    while(!pq.empty())
    {
        int v=pq.top().second;
        pq.pop();
        if(bio[v])continue;
        bio[v]=true;

        for(auto x:p[v])
        {
            for(int i=v%x;i<n;i+=x)
            {
                if(dis[i]>dis[v]+(abs(i-v))/x)
                {
                    dis[i]=dis[v]+(abs(i-v))/x;
                    if(i==e)
                    {
                        cout<<dis[i]<<endl;
                        return 0;
                    }
                    pq.push({-dis[i],i});
                }
            }
        }
    }

    cout<<"-1"<<endl;
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:37:5: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
     if(e==s)
     ^~
skyscraper.cpp:65:21: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
                     if(i==e)
                     ^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1148 KB Output is correct
3 Correct 3 ms 1216 KB Output is correct
4 Correct 3 ms 1216 KB Output is correct
5 Correct 3 ms 1336 KB Output is correct
6 Correct 3 ms 1336 KB Output is correct
7 Correct 3 ms 1336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1336 KB Output is correct
2 Correct 3 ms 1336 KB Output is correct
3 Correct 3 ms 1336 KB Output is correct
4 Correct 3 ms 1336 KB Output is correct
5 Correct 3 ms 1344 KB Output is correct
6 Correct 3 ms 1344 KB Output is correct
7 Correct 3 ms 1344 KB Output is correct
8 Correct 3 ms 1344 KB Output is correct
9 Incorrect 3 ms 1344 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1344 KB Output is correct
2 Correct 2 ms 1344 KB Output is correct
3 Correct 3 ms 1344 KB Output is correct
4 Correct 3 ms 1344 KB Output is correct
5 Correct 3 ms 1344 KB Output is correct
6 Correct 3 ms 1344 KB Output is correct
7 Correct 3 ms 1344 KB Output is correct
8 Correct 3 ms 1344 KB Output is correct
9 Incorrect 3 ms 1344 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1344 KB Output is correct
2 Correct 3 ms 1344 KB Output is correct
3 Correct 3 ms 1344 KB Output is correct
4 Correct 3 ms 1344 KB Output is correct
5 Correct 2 ms 1344 KB Output is correct
6 Correct 2 ms 1344 KB Output is correct
7 Correct 2 ms 1344 KB Output is correct
8 Correct 2 ms 1344 KB Output is correct
9 Incorrect 2 ms 1344 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1344 KB Output is correct
2 Correct 3 ms 1344 KB Output is correct
3 Correct 3 ms 1344 KB Output is correct
4 Correct 3 ms 1344 KB Output is correct
5 Correct 3 ms 1344 KB Output is correct
6 Correct 2 ms 1344 KB Output is correct
7 Correct 2 ms 1344 KB Output is correct
8 Correct 2 ms 1344 KB Output is correct
9 Incorrect 3 ms 1344 KB Output isn't correct
10 Halted 0 ms 0 KB -