This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int n, m, zg[2009], sk[2009], tmp, v[2009][2009];
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 sum + 60000009;
if (pos == 1) return sum;
int mini = 60000009;
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]; }
cout << reks(0, 0); return 0;
}
// if (bio[zg[1]] > n*n) cout << -1;
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |