Submission #1027347

#TimeUsernameProblemLanguageResultExecution timeMemory
1027347MuhammetJakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
1094 ms1884 KiB
#include <bits/stdc++.h> using namespace std; #define N 30001 #define ll long long int #define sz(x) (int)x.size() #define ff first #define ss second const ll M = 30000000; ll T, n, m, b[N], p[N], d[N]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for(int i = 0; i < m; i++){ cin >> b[i] >> p[i]; d[i] = M; } d[0] = 0; ll x = 0; vector <ll> v; for(int i = 1; i < m; i++) v.push_back(i); while(sz(v) > 0){ ll mn = M, ind = x; for(auto i : v){ ll k = (abs(b[i]-b[x])); if(d[i] < mn) ind = i; mn = min(d[i],mn); if(k % p[x] != 0) continue; d[i] = min(d[x] + (k/p[x]), d[i]); if(d[i] < mn) ind = i; mn = min(d[i],mn); } if(x == ind) break; x = ind; if(x == 1) break; for(int i = 0; i < sz(v); i++){ if(v[i] == ind){ v.erase(v.begin() + i); break; } } } if(d[1] == M) d[1] = -1; cout << d[1]; return 0; }
#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...