Submission #766346

#TimeUsernameProblemLanguageResultExecution timeMemory
766346Gabi88Jakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
98 ms262144 KiB
#include<bits/stdc++.h> using namespace std; int n, m, zg[30009], sk[30009], tmp, v[20009][20009]; int reks(int pos, int sum){ if (v[0][pos] == -1 or v[0][pos] > sum) v[0][pos] = sum; else if (v[0][pos] < sum) return n*n+30; if (pos == 1){ if (v[0][1] == -1) return v[0][1] = sum; else return v[0][1] = min(v[0][1], sum); } int mini = n*n+20; for(int i=0; i<m; i++){ if (abs(zg[i] - zg[pos]) % sk[pos] == 0 and i != pos){ if (v[pos][i] == -1) v[pos][i] = abs(zg[i] - zg[pos]) / sk[pos]; if (v[0][i] == -1 or v[0][i] > v[0][pos] + v[pos][i]) v[0][i] = v[0][pos] + v[pos][i]; mini = min(reks(i, sum + v[pos][i]), mini); } } return mini; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; memset(v, -1, sizeof v); for(int i=0; i<m; i++) cin >> zg[i] >> sk[i]; tmp = reks(0, 0); if (tmp > n*n) cout << -1; else cout << tmp; 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...