Submission #695237

#TimeUsernameProblemLanguageResultExecution timeMemory
695237Mizo_CompilerJakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
235 ms262144 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 = 2e5+5; //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; } for(int i = 0; i < m;i++){ cin >> id[i]; cin >> p[i]; int cnt = 1; for(int j = id[i]+p[i]; j < n;j += p[i]){ adj[id[i]].pb({j , cnt++}); } cnt = 1; for(int j = id[i]-p[i]; j >= 0;j -= p[i]){ adj[id[i]].pb({j , cnt++}); } } 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...