#include <bits/stdc++.h>
#define int long long
#define float double
#define pb push_back
#define F first
#define S second
#define T int t; cin >> t; while(t--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
/// Benzema is the best player in the world
const int N = 1e6 + 6;
const int M = 1e3 + 3;
const int mod = 1e9 + 7;
const int inf = 1e9;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int LOG = 28;
int n, m;
int p[N], dist[N];
vector<int> v[N];
priority_queue<pair<int, int>> q;
bool vis[N];
void dij() {
for(int i = 1; i <= n; i++) dist[i] = inf;
q.push({0, 1});
dist[1] = 0;
while(!q.empty()) {
int u = q.top().S;
q.pop();
for(auto x: v[u]) {
int i = u, cnt = 0;
while(i >= 1) {
if (dist[i] > dist[u] + cnt)
dist[i] = dist[u] + cnt, q.push({-dist[i], i});
i -= p[x];
cnt++;
}
cnt = 0, i = u;
while(i <= n) {
if (dist[i] > dist[u] + cnt)
dist[i] = dist[u] + cnt, q.push({-dist[i], i});
i += p[x];
cnt++;
}
}
}
}
main() {
IOS
cin >> n >> m;
for(int i = 1; i <= m; i++) {
int b;
cin >> b >> p[i];
v[b + 1].push_back(i);
}
dij();
cout << dist[2];
}
Compilation message
skyscraper.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
51 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23704 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Incorrect |
11 ms |
23740 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23804 KB |
Output is correct |
3 |
Incorrect |
12 ms |
23764 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23704 KB |
Output is correct |
3 |
Incorrect |
14 ms |
23764 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23764 KB |
Output is correct |
3 |
Incorrect |
12 ms |
23780 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23784 KB |
Output is correct |
2 |
Correct |
15 ms |
23800 KB |
Output is correct |
3 |
Incorrect |
12 ms |
23708 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |