Submission #164127

#TimeUsernameProblemLanguageResultExecution timeMemory
164127muhammad_hokimiyonJakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
411 ms262148 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #define fi first #define se second #define LL long long using namespace std; const int B = 317; const int N = 3e4 + 7; const int maxn = 1e5 + 7; const LL mod = 1e9 + 7; const LL mod1 = 1e9 + 9; const int inf = 1e9 + 100; LL n,m; LL a[N]; LL b[N]; LL d[N]; LL h[N]; priority_queue< pair < LL , LL > > q; vector < pair < LL , LL > > v[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen( "input.txt" , "r" , stdin ); //sfreopen( "output.txt" , "w" , stdout ); cin >> n >> m; for( int i = 0; i < m; i++ ){ cin >> a[i] >> b[i]; h[a[i]] = 1; } for( int i = 0; i <= n; i++ )d[i] = 1e18; for( int i = 0; i < m; i++ ){ LL f = a[i]; LL cnt = 1; while( f + b[i] <= n ){ f += b[i]; if( h[f] )v[a[i]].push_back({ f , cnt }); cnt++; } f = a[i]; cnt = 1; while( f - b[i] >= 0 ){ f -= b[i]; if( h[f] )v[a[i]].push_back({ f , cnt }); cnt++; } } d[a[0]] = 0; q.push({0 , a[0]}); while( !q.empty() ){ LL x = q.top().se; q.pop(); for( auto y : v[x] ){ if( d[x] + y.se < d[y.fi] ){ d[y.fi] = d[x] + y.se; q.push({ -d[y.fi] , y.fi }); } } } if( d[a[1]] == 1e18 )d[a[1]] = -1; cout << d[a[1]]; //cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; }
#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...