이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define vec vector<int>
#define dead not_bad
#define left not_right
#define y1 what
using namespace std;
const int N = (int) 3e4 + 10;
const int M = (int) 2e4 + 10;
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const double PI = 3.14159265359;
const double EPS = (double) 1e-9;
int nx[8] = {-1, -2, -2, -1, 1, 1, 2, 2};
int ny[8] = {-2, -1, 1, 2, -2, 2, -1, 1};
int n, m;
int b[N], p[N];
ll d[N];
vector<pii> v[N];
int main() {
#define fn "teams"
#ifdef witch
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
//freopen(fn".in", "r", stdin);
//freopen(fn".out", "w", stdout);
#endif
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> b[i] >> p[i];
d[i] = LINF;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
if (i == j)
continue;
int e = INF;
if ((b[j] - b[i]) % p[i] == 0) {
e = min(e, abs(b[j] - b[i]) / p[i]);
}
if (e < INF) {
// cout << i << ' ' << j << ' ' << e << endl;
v[i].pb(mp(j, e));
}
}
}
set<pair<ll, int> > st;
st.insert(mp(0, 0));
d[0] = 0;
while (!st.empty()) {
int fr = st.begin() -> s;
st.erase(st.begin());
for (auto it : v[fr]) {
if (d[fr] + it.s < d[it.f]) {
st.erase(mp(d[it.f], it.f));
d[it.f] = d[fr] + it.s;
st.insert(mp(d[it.f], it.f));
}
}
}
if (d[1] == LINF)
d[1] = -1;
cout << d[1];
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... |