Submission #330671

# Submission time Handle Problem Language Result Execution time Memory
330671 2020-11-26T06:09:09 Z fammo Jakarta Skyscrapers (APIO15_skyscraper) C++11
10 / 100
2 ms 1280 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
const int MAXN = 30000 + 7;
int n, m, p[MAXN], b[MAXN], dis[MAXN];
vector<int>adj[MAXN];
inline void dij(int root){
    priority_queue<pair<int, int>>s;
    fill(dis, dis + MAXN, INT_MAX/2);
    dis[root] = 0;
    s.push({0, root});
    while(!s.empty()){
        auto x = s.top();
        int v = x.second, d = -x.first;
        s.pop();
        if(d > dis[v])continue;
        if(v == b[1] || dis[v] == INT_MAX/2)return;
        for(auto p : adj[v]){
            int cnt = 1;
            for(int u = v + p; u < n; u += p){
                if(d + cnt < dis[u]){
                    dis[u] = d + cnt;
                    s.push({-dis[u], u});
                }
                cnt ++;
            }
            cnt = 1;
            for(int u = v - p; u > -1; u -= p){
                if(d + cnt < dis[u]){
                    dis[u] = d + cnt;
                    s.push({-dis[u], u});
                }
                cnt ++;
            }
        }
    }
    return;
}
int32_t main(){
    //ios_base::sync_with_stdio(0), cin.tie(nullptr), cout.tie(nullptr);
    //cin >> n >> m;
    scanf("%d", &n);
    scanf("%d", &m);
    for(int i = 0; i < m; i ++){
        //cin >> b[i] >> p[i];
        scanf("%d", b + i);
        scanf("%d", p + i);
        adj[b[i]].pb(p[i]);
    }
    dij(0);
    printf("%d\n", (dis[b[1]] >= INT_MAX/2? -1 : dis[b[1]]));
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
skyscraper.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |     scanf("%d", &m);
      |     ~~~~~^~~~~~~~~~
skyscraper.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |         scanf("%d", b + i);
      |         ~~~~~^~~~~~~~~~~~~
skyscraper.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |         scanf("%d", p + i);
      |         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
8 Incorrect 1 ms 1132 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
8 Incorrect 1 ms 1164 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1280 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
8 Incorrect 1 ms 1132 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 2 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
8 Incorrect 2 ms 1280 KB Output isn't correct
9 Halted 0 ms 0 KB -