이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
* author: NeroZein
* created: 04.02.2023 22:58:06
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 2003;
int n, m;
int b[N];
int p[N];
int g[N][N];
inline void minSelf(int& x, int y) {
x = min(x, y);
}
int ans;
int cost[N];
inline void dij() {
priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
memset(cost, 0x3f3f3f3f, sizeof cost);
cost[b[0]] = 0;
pq.emplace(0, b[0]);
while (!pq.empty()) {
auto src = pq.top();
pq.pop();
if (src.second == b[1]) {
cout << src.first << '\n';
exit(0);
}
if (src.first != cost[src.second]) {
continue;
}
for (int i = 0; i < n; ++i) {
if (src.first + g[src.second][i] < cost[i]) {
cost[i] = src.first + g[src.second][i];
pq.emplace(cost[i], i);
}
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
memset(g, 0x3f3f3f3f, sizeof g);
for (int i = 0; i < m; ++i) {
cin >> b[i] >> p[i];
for (int j = 1; j < n; ++j) {
int l = b[i] - j * p[i];
int r = b[i] + j * p[i];
if (r < n) {
minSelf(g[b[i]][r], j);
}
if (l >= 0) {
minSelf(g[b[i]][l], j);
}
}
}
ans = INT_MAX;
dij();
cout << -1 << '\n';
return 0;
}
# | 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... |