Submission #954792

# Submission time Handle Problem Language Result Execution time Memory
954792 2024-03-28T14:39:10 Z BbtT Jakarta Skyscrapers (APIO15_skyscraper) C++17
0 / 100
1 ms 348 KB
#include<bits/stdc++.h>

using namespace std;

struct edge{
    long long int n,w;
};

bool operator<(edge a,edge b){
    if(a.w==b.w)return a.n<b.n;
    return a.w<b.w;
}

int main(){

    long long int N,M;
    cin>>N>>M;
    vector<vector<edge>> edges(N);
    for(int i=0;i<M;i++){
        long long int b,p;
        scanf("%lld%lld",&b,&p);
        vector<edge> temp;
        for(int j=b-p;j>=0;j-=p)temp.push_back((edge){j,(b-j)/p});
        for(int j=b+p;j<N;j+=p)temp.push_back((edge){j,(j-b)/p});
        edges.push_back(temp);
        edges[b].push_back((edge){edges.size()-1,0});
    }

    // for(int ad=0;ad<edges.size();ad++){
    //     cout<<ad<<endl;
    //     for(auto i:edges[ad])cout<<i.n<<" "<<i.w<<"\t";cout<<endl;
    // }

    bitset<30005> vis;
    priority_queue<edge> pq;
    vis[0]=1;
    pq.push((edge){0,0});
    while(!pq.empty()){
        edge cur_edge=pq.top();
        pq.pop();
        vis[cur_edge.n]=1;
        if(cur_edge.n==1){
            cout<<cur_edge.w<<endl;
            return 0;
        }
        for(auto togo: edges[cur_edge.n]){
            if(vis[togo.n])continue;
            pq.push((edge){togo.n,cur_edge.w+togo.w});
        }
    }

    cout<<-1<<endl;

    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:26:47: warning: narrowing conversion of '(edges.std::vector<std::vector<edge> >::size() - 1)' from 'std::vector<std::vector<edge> >::size_type' {aka 'long unsigned int'} to 'long long int' [-Wnarrowing]
   26 |         edges[b].push_back((edge){edges.size()-1,0});
      |                                   ~~~~~~~~~~~~^~
skyscraper.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%lld%lld",&b,&p);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -