#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define lg long long
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//Jakarta Skyscraper
const lg N = 30005;
lg dist[N];
vector<pair<lg, lg>> adj[N];
vector<lg> b(N), p(N);
void dijkstra(lg src)
{
priority_queue<array<lg, 2>> pq;
pq.push({0, src});
memset(dist, 0x3f, sizeof(dist));
dist[src] = 0;
while(pq.size())
{
lg x = pq.top()[1];
pq.pop();
for(auto [it, c] : adj[x])
{
if(dist[it] > dist[x]+c)
{
dist[it] = dist[x]+c;
pq.push({-dist[it], it});
}
}
}
return;
}
int main()
{
fastio;
lg n, m;
cin >> n >> m;
for(int i = 0; i < m; i++)
{
cin >> b[i] >> p[i];
}
for(int i = 0; i < m; i++)
{
lg x = b[i]+p[i], z = 1;
while(x < n)
{
adj[b[i]].push_back({x, z});
z++;
x += p[i];
}
x = b[i]-p[i];
z = 1;
while(x >= 0)
{
adj[b[i]].push_back({x, z});
z++;
x -= p[i];
}
}
dijkstra(b[0]);
cout << dist[b[1]] << '\n';
return 0;
}
Compilation message
skyscraper.cpp: In function 'void dijkstra(long long int)':
skyscraper.cpp:29:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
29 | for(auto [it, c] : adj[x])
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1748 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1748 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1620 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1748 KB |
Output is correct |
2 |
Correct |
1 ms |
1748 KB |
Output is correct |
3 |
Correct |
1 ms |
1620 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1640 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1688 KB |
Output is correct |
2 |
Correct |
1 ms |
1748 KB |
Output is correct |
3 |
Correct |
1 ms |
1620 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1748 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1748 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1620 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1748 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1620 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1620 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1748 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |