Submission #1110732

# Submission time Handle Problem Language Result Execution time Memory
1110732 2024-11-10T09:40:26 Z vjudge1 Jakarta Skyscrapers (APIO15_skyscraper) C++17
0 / 100
2 ms 1884 KB
/**------------------------------------------
---------Author: BePhuong--------------------
---------From: TK4-CHT ----------------------
---------Training To Win Voi 25 !!! ---------
---------------------------------------------
--------------------PhamVuPhuong2008<BeL>-**/

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define int long long
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii, ii>
#define base 341
#define MASK(i) (1ll << i)
#define oo 1e18
#define isOn(x,i) ((x) & MASK(i))
#define bitOn(x,i) ((x) | MASK(i))
#define bitOff(x,i) ((x) & ~MASK(i))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define __lcm(a,b) (1ll * ((a) / __gcd((a), (b))) * (b))
using namespace std;
//using namespace __gnu_pbds;
const int maxn = 5e4 + 5;
int n,m,  dist[maxn], b[maxn];
vector<int> a[maxn];
void djk(int st) {
    memset(dist, 0x3f, sizeof dist);
    priority_queue<ii, vector<ii>, greater<ii>> q;
    dist[st] = 0;
    q.push({0, st});
    while(!q.empty()) {
        int cost = q.top().fi, z = q.top().se;
//        int z = q.front();
        q.pop();
        if (cost > dist[z]) continue;
        for (int cost : a[z]) {
            for (int i = 1; z + i*cost < n; i++) {
                if (dist[z + i*cost] > dist[z] + i) {
                    dist[z + i*cost] = dist[z] + i;
                    q.push({dist[z + i*cost], z + i*cost});
                }
            }
            for (int i = 1; z - i*cost > 0; i++) {
                if (dist[z - i*cost] > dist[z] + i) {
                    dist[z - i*cost] = dist[z] + i;
                    q.push({dist[z - i*cost], z - i*cost});
                }
            }
        }
    }
}
main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> b[i];
        int x; cin >> x;
        a[b[i]].pb(x);
    }
//    for (int i = 1; i <= n; i++) cout << a[i] << endl;
    djk(b[0]);
    if (dist[b[1]] == 2e18) cout << "-1";
    else cout << dist[b[1]];
}

Compilation message

skyscraper.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1872 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Incorrect 2 ms 1872 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1872 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Incorrect 2 ms 1872 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1872 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Incorrect 2 ms 1872 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1884 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Incorrect 2 ms 1872 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1872 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Incorrect 2 ms 1872 KB Output isn't correct
5 Halted 0 ms 0 KB -