제출 #1147565

#제출 시각아이디문제언어결과실행 시간메모리
1147565Theo830Jakarta Skyscrapers (APIO15_skyscraper)C++20
36 / 100
1096 ms840 KiB
#include <bits/stdc++.h> using namespace std; typedef int ll; const ll INF = 1e9+7; const ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<ii,ll> #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///Training int main(void){ ios_base::sync_with_stdio(0); cin.tie(0); ll n,m; cin>>n>>m; ll b[m],p[m]; vector<ll>ex[n]; f(i,0,m){ cin>>b[i]>>p[i]; ex[b[i]].pb(p[i]); } bool done[m] = {0}; ll best[m]; f(i,0,m){ best[i] = INF; } best[0] = 0; ll ek = m; while(ek--){ ll mini = INF+1; ll pos = -1; f(i,0,m){ if(!done[i] && mini > best[i]){ pos = i; mini = best[i]; } } done[pos] = 1; f(j,0,m){ if(!done[j] && abs(b[pos] - b[j]) % p[pos] == 0){ best[j] = min(best[j],abs(b[pos] - b[j]) / p[pos] + best[pos]); } } } ll ans = best[1]; if(ans == INF){ ans = -1; } cout<<ans<<"\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...