# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
411705 | MasterTaster | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 2 ms | 1612 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define INF 1000000000000010LL
#define MAXN 30010
using namespace std;
ll d[MAXN];
int n, m;
vector<int> g[MAXN];
vector<ll> w[MAXN];
void dijkstra(int s)
{
for (int i=0; i<n; i++) d[i]=INF;
d[s]=0;
priority_queue< pair<int, ll>, vector< pair<int, ll> >, greater< pair<int, ll> > > q;
q.push({0, s});
while (!q.empty())
{
int u=q.top().second;
ll du=q.top().first;
q.pop();
if (du!=d[u]) continue;
for (int i=0; i<g[u].size(); i++)
{
int v=g[u][i];
if (d[u]+w[u][i]<d[v])
{
d[v]=d[u]+w[u][i];
q.push({d[v], v});
}
}
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>m;
for (int i=0; i<m; i++)
{
int u; cin>>u;
int p; cin>>p;
for (int j=1; u-j*p>=0; j++) { g[u].pb(u-j*p); w[u].pb(j); }
for (int j=1; u+j*p<n; j++) { g[u].pb(u+j*p); w[u].pb(j); }
}
dijkstra(0);
if (d[1]==INF) cout<<-1;
else cout<<d[1];
}
Compilation message (stderr)
# | 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... |