제출 #695247

#제출 시각아이디문제언어결과실행 시간메모리
695247Mizo_CompilerJakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
1095 ms65304 KiB
#include <bits/stdc++.h> using namespace std; #define MOEZ ios_base::sync_with_stdio(false);cin.tie(NULL),cout.tie(NULL); typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define F first #define S second #define pb push_back #define all(v) v.begin() , v.end() #define eb emplace_back #define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());} #define mem(d , x) memset(d , x , sizeof(d)); #define sz(x) (int)x.size() const int N = 30005; //const ll M = 1e9+7; //const ll inf = 1e18; //const ld eps = 1e-6; #define int long long int n , id[N] , p[N] , m; vector<pair<int , int>>adj[N]; int d[N]; signed main(){ MOEZ cin >> n >> m; for(int i = 0; i < n;i++){ d[i] = 1e18; } vector<int>v; for(int i = 0; i < m;i++){ cin >> id[i]; cin >> p[i]; v.pb(id[i]); } sort(all(v)); for(int i = 0; i < m;i++){ for(auto x:v){ if(x >= id[i])break; if((id[i]-x)%p[i] == 0){ adj[id[i]].pb({x , (id[i]-x)/p[i]}); } } for(int j = m-1; v[j] > id[i];j--){ if((v[j]-id[i])%p[i] == 0)adj[id[i]].pb({v[j] , (v[j]-id[i])/p[i]}); } } priority_queue<pair<int , int> , vector<pair<int , int>> , greater<>>q; q.push({id[0] , 0}); d[id[0]] = 0; while(!q.empty()){ int u = q.top().F , cost = q.top().S; q.pop(); if(d[u] < cost)continue; for(auto x:adj[u]){ int v = x.F , nc = cost+x.S; if(nc < d[v]){ d[v] = nc; q.push({v , nc}); } } } cout << (d[id[1]] == 1e18 ? -1 : d[id[1]]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...