Submission #953770

# Submission time Handle Problem Language Result Execution time Memory
953770 2024-03-26T15:53:48 Z tnknguyen_ Jakarta Skyscrapers (APIO15_skyscraper) C++14
10 / 100
2 ms 6800 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n' 
#define pii pair<int, int>

const int MX = 3e5 + 5;
int INF;
int vi[MX], b[MX], p[MX];
int d[MX];
int n, m;

// ------------ FUNCTIONS -----------
void bfs(){
    memset(d, 63, sizeof d);
    INF = d[0];
    priority_queue<pii> q;
    q.push({0, 1});
    d[b[1]] = 0; 

    int c = 0;
    while(q.size() && c <= 10){
        ++c;
        int w, u;
        tie(w, u) = q.top();
        w = -w;
        q.pop();

        for(int i=1; i<=m; ++i){
            int v = b[i];
            int c = abs(b[u] - v) / p[u];
            if(abs(b[u] - v) % p[u] == 0 && w + c < d[v]){
                d[v] = w + c;
                q.push({-d[v], i});
            }
        }
    }
}

// ------------ SUBTASKS ------------
namespace SUB123{
    bool ok(){
        return (n <= 2000 && m <= 2000);
    }

    void solve(){
        bfs();
        cout<<(d[b[2]] == INF ? -1 : d[b[2]]);

        //---------------------
        exit(0);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //freopen("main.inp","r",stdin);
    //freopen("main.out","w",stdout);

    cin>>n>>m;

    for(int i=1; i<=m; ++i){
        cin>>b[i]>>p[i];
    }

    if(SUB123 :: ok){
        SUB123 :: solve();
        return 0;
    }

    return 0;
}

Compilation message

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:69:18: warning: the address of 'bool SUB123::ok()' will never be NULL [-Waddress]
   69 |     if(SUB123 :: ok){
      |        ~~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 1 ms 6744 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 2 ms 6744 KB Output is correct
3 Correct 1 ms 6744 KB Output is correct
4 Correct 1 ms 6604 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6604 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Incorrect 1 ms 6748 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 1 ms 6604 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Incorrect 1 ms 6748 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6800 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6608 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Incorrect 1 ms 6748 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Incorrect 1 ms 6748 KB Output isn't correct
10 Halted 0 ms 0 KB -