Submission #146355

#TimeUsernameProblemLanguageResultExecution timeMemory
146355muhammad_hokimiyonJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
3 ms1016 KiB
#include <bits/stdc++.h> //#pragma GCC optimize("Ofast") #define LL long long #define se second #define fi first using namespace std; const int N = 3e4 + 7; const int mod = 1e9 + 7; const int B = sqrt(N); LL n,m; LL a[N]; LL b[N]; LL d[N]; vector < pair < LL , LL > > v[N]; int main() { ios_base::sync_with_stdio(0); //freopen( "input.txt" , "r" , stdin ); //freopen( "output.txt" , "w" , stdout ); cin >> n >> m; for( int i = 0; i < m; i++ ){ cin >> a[i] >> b[i]; } for( int i = 1; i <= n; i++ )d[i] = 2e18; for( int i = 0; i < m; i++ ){ for( int j = 0; j < m; j++ ){ if( i == j )continue; if( abs( a[i] - a[j] ) % b[i] == 0 ){ v[a[i]].push_back({ a[j] , abs( a[i] - a[j] ) / b[i] }); } } } queue < LL > q; q.push(0); d[0] = 0; while( !q.empty() ){ LL x = q.front(); q.pop(); for( auto y : v[x] ){ if( d[x] + y.se < d[y.fi] ){ q.push(y.fi); d[y.fi] = d[x] + y.se; } } } if( d[1] == 2e18 )d[1] = -1; cout << d[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...