이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAX = (2e3)+1, INF = 1e9;
int n, m, b[MAX], p[MAX], d[MAX], g[MAX][MAX];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
fill(d+1, d+m, INF);
for(int i = 0; i < m; i++) for(int j = 0; j < m; j++) if(i != j) g[i][j] = INF;
for(int i = 0; i < m; i++) cin >> b[i] >> p[i];
for(int i = 0; i < m; i++) for(int j = 0; j < m; j++) if(i != j) {
if(abs(b[i] - b[j]) % p[i] == 0) g[i][j] = abs(b[i] - b[j]) / p[i];
}
unordered_set<int> st;
for(int i = 0; i < m; i++) st.insert(i);
while(!st.empty()) {
int u = *st.begin();
for(int v: st) if(d[v] < d[u]) u = v;
st.erase(u);
for(int v = 0; v < m; v++) if(d[u] + g[u][v] < d[v]) {
d[v] = d[u] + g[u][v];
}
}
cout << (d[1] == INF ? -1 : d[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... |