답안 #397326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
397326 2021-05-01T22:28:22 Z Bitmasking Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
28 ms 47288 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(ini) (ll) __builtin_popcountll(x)
#define cuantos(a,x) count(all(a),x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) <<"\n"
#define test ll deftestcases;cin>>deftestcases;while(deftestcases--)
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii;
typedef vector<ll>  vi;
typedef vector<ii> vii;
template<class T> using ordered_set =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
const ll inf = 2e18;
const ll mod = 1e9+7;   
const ll MAX = 1e6+10;

vii adj[MAX];
vi aux[MAX];
ll dis[MAX];
void dijkstra(ll root,ll n){
    f(i,0,n+4){
        dis[i] = -1;
    }
    priority_queue<ii,vii,greater<ii>> pq;
    dis[root] = 0;
    pq.push({dis[root],root});
    while(sz(pq)){
        ll u = pq.top().sc;
        ll d = pq.top().fs;
        pq.pop();
        if(dis[u]!=d) continue;
        for(auto v : adj[u]){
            ll to = v.fs,w = v.sc;
            if(dis[to]==-1 || dis[u]+w<dis[to]){
                dis[to] = dis[u]+w;
                pq.push({dis[to],to});
            }
        }
    }
}

void ida(ll u,ll n){
    for(auto pod : aux[u]){
            ll to = 0,mul=1;
            while(to<n){
                to = pod*mul+u;
                if(to>n) break;
                adj[u].pb({to,mul});
                mul++;
            }
    }
}
void vuelta(ll u){
    for(auto pod : aux[u]){
        ll to = 0,mul=1;
        while(to>0){
            to = u-pod*mul;
            if(to<0) break;
            adj[u].pb({to,mul});
            mul++;
        }
    }
}
int main(){
    fastio;
    ll n,m;cin>>n>>m;
    ll ini=0,meta=0;
    f(i,0,m){
        ll b,p;cin>>b>>p;
        if(!i) ini = b;
        if(i==1) {meta = b;}
        aux[b].pb(p);
    }
    f(u,0,n){
        ida(u,n);
        vuelta(u);
    }
    dijkstra(ini,n);
    cout<<dis[meta]<<"\n";
    return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 47172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 47288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 47260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 47224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 47200 KB Output isn't correct
2 Halted 0 ms 0 KB -