Submission #73661

# Submission time Handle Problem Language Result Execution time Memory
73661 2018-08-28T16:45:10 Z Vardanyan Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
3 ms 868 KB
//#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
const int N = 10007;
vector<pair<pair<int,int>,int> > g[N];
int B[N],P[N];
int dist[N][N];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 0;i<m;i++){
        int b,p;
        scanf("%d%d",&b,&p);
        B[i] = b;
        P[i] = p;
        int bb = b;
        int c = 1;
        while(bb+p<n){
            bb+=p;
            g[b].push_back({{bb,p},c});
            c++;
        }
        bb = b;
        c = 1;
        while(bb-p>=0){
            bb-=p;
            g[b].push_back({{bb,p},c});
            c++;
        }
    }
    priority_queue<pair<int,pair<int,int> > > pq;
    for(int i = 1;i<=n;i++)
        for(int j = 1;j<=n;j++)
        dist[i][j] = 1000*1000*1000+7;
    for(int i = 0;i<m;i++){
        if(B[i] == 0){
            dist[0][P[i]] = 0;
            pq.push({0,{B[i],P[i]}});
        }
    }
    int ans = -1;
    while(!pq.empty()){
        pair<int,pair<int,int> > v = pq.top();
        pq.pop();
        int gag = v.second.first;
        for(int i = 0;i<g[gag].size();i++){
            int to = g[gag][i].first.first;
            int d = g[gag][i].second;
            if(d+(-v.first)<dist[to][g[gag][i].first.second]){
                dist[to][g[gag][i].first.second] = d+(-v.first);
                pq.push({-dist[to][g[gag][i].first.second],{to,g[gag][i].first.second}});
                if(to == 1 && (ans == -1 || ans>dist[to][g[gag][i].first.second])) ans = dist[to][g[gag][i].first.second];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:47:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0;i<g[gag].size();i++){
                       ~^~~~~~~~~~~~~~
skyscraper.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&b,&p);
         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Incorrect 3 ms 640 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 692 KB Output is correct
2 Incorrect 3 ms 692 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 744 KB Output is correct
2 Incorrect 3 ms 744 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 800 KB Output is correct
2 Incorrect 2 ms 848 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 868 KB Output is correct
2 Incorrect 3 ms 868 KB Output isn't correct
3 Halted 0 ms 0 KB -