Submission #953773

# Submission time Handle Problem Language Result Execution time Memory
953773 2024-03-26T15:55:00 Z tnknguyen_ Jakarta Skyscrapers (APIO15_skyscraper) C++14
10 / 100
2 ms 7000 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; 

    while(q.size()){
        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;
}
# 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 6748 KB Output is correct
4 Correct 1 ms 7000 KB Output is correct
5 Correct 1 ms 6752 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 1 ms 6760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6752 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6760 KB Output is correct
4 Correct 1 ms 6756 KB Output is correct
5 Correct 1 ms 6752 KB Output is correct
6 Correct 1 ms 6752 KB Output is correct
7 Correct 1 ms 6760 KB Output is correct
8 Correct 1 ms 6756 KB Output is correct
9 Incorrect 1 ms 6760 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6756 KB Output is correct
2 Correct 1 ms 6808 KB Output is correct
3 Correct 1 ms 6756 KB Output is correct
4 Correct 1 ms 6752 KB Output is correct
5 Correct 1 ms 6756 KB Output is correct
6 Correct 1 ms 6772 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6760 KB Output is correct
9 Incorrect 1 ms 6752 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6760 KB Output is correct
2 Correct 1 ms 6756 KB Output is correct
3 Correct 1 ms 6760 KB Output is correct
4 Correct 1 ms 6756 KB Output is correct
5 Correct 1 ms 6756 KB Output is correct
6 Correct 1 ms 6756 KB Output is correct
7 Correct 1 ms 6756 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 6748 KB Output is correct
5 Correct 1 ms 6752 KB Output is correct
6 Correct 1 ms 6756 KB Output is correct
7 Correct 1 ms 6752 KB Output is correct
8 Correct 2 ms 6620 KB Output is correct
9 Incorrect 1 ms 6752 KB Output isn't correct
10 Halted 0 ms 0 KB -