Submission #1004771

#TimeUsernameProblemLanguageResultExecution timeMemory
1004771codexistentJakarta Skyscrapers (APIO15_skyscraper)C++14
10 / 100
1 ms604 KiB
#include <iostream> #include <vector> #include <set> using namespace std; #define FOR(i, a, b) for(long long i = a; i <= b; i++) #define MAXN 30005 long long n, m, t[MAXN], s, e; long long p[MAXN]; set<long long> a; int main(){ cin >> n >> m; FOR(i, 0, n - 1) t[i] = -1, p[i] = -1; FOR(i, 0, m - 1){ int b, pi; cin >> b >> pi; if(i == 0) s = b, t[b] = 0; if(i == 1) e = b; p[b] = pi; } FOR(i, 0, n - 1) if(i != s) a.insert(i); long long c = s; pair<long long, long long> nx = make_pair(-1, -1); while(c != -1){ for(long long i : a){ if(p[c] != -1 && abs(i - c) % p[c] == 0){ t[i] = (t[i] == -1) ? (t[c] + abs(i - c) / p[c]) : min(t[i], t[c] + abs(i - c) / p[c]); } nx.first = t[i]; nx.second = i; } a.erase(c); c = nx.second; nx.first = nx.second = -1; } cout << t[e] << endl; }
#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...