Submission #1109594

# Submission time Handle Problem Language Result Execution time Memory
1109594 2024-11-07T06:42:12 Z simona1230 Jakarta Skyscrapers (APIO15_skyscraper) C++17
0 / 100
2 ms 1104 KB
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
struct edge
{
    int x,d;
    edge(){}
    edge(int _x,int _d)
    {
        x=_x;
        d=_d;
    }

    bool operator<(const edge&e)const
    {
        return e.d<d;
    }
};

int n,m;
vector<edge> v[32001];
void read()
{
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        for(int j=x+y;j<n;j+=y)
        {
            //cout<<i<<" "<<j+m<<endl;
            v[i].push_back({j+m,(j-x)/y});
        }

        for(int j=x-y;j>=0;j-=y)
        {
            //cout<<i<<" "<<j+m<<endl;
            v[i].push_back({j+m,(x-j)/y});
        }

        //cout<<x+m<<" "<<i<<endl;
        v[x+m].push_back({i,0});
    }
}

int d[32001];
priority_queue<edge> q;
void dijkstra()
{
    for(int i=0;i<n+m;i++)
        d[i]=1e9;

    d[0]=0;
    q.push({0,0});
    while(q.size())
    {
        edge e=q.top();
        //cout<<e.x<<endl;
        q.pop();

        if(d[e.x]>=e.d)
        {
            for(int i=0;i<v[e.x].size();i++)
            {
                edge nb=v[e.x][i];
                if(nb.d+e.d<d[nb.x])
                {
                    d[nb.x]=nb.d+e.d;
                    q.push({nb.x,d[nb.x]});
                }
            }
        }
    }
}

int main()
{
    read();
    dijkstra();
    if(d[1]==1e9)d[1]=-1;
    cout<<d[1]<<endl;
    return 0;
}

Compilation message

skyscraper.cpp: In function 'void dijkstra()':
skyscraper.cpp:63:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             for(int i=0;i<v[e.x].size();i++)
      |                         ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1104 KB Output is correct
2 Incorrect 2 ms 1104 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1104 KB Output is correct
2 Incorrect 1 ms 1104 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1104 KB Output is correct
2 Incorrect 1 ms 1104 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1104 KB Output is correct
2 Incorrect 1 ms 1104 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1104 KB Output is correct
2 Incorrect 1 ms 1104 KB Output isn't correct
3 Halted 0 ms 0 KB -