# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
119139 | Charis02 | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 819 ms | 6512 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<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 30004
#define INF 1e9+7
using namespace std;
ll pos[N],jump[N],n,m,d[N];
vector < vector < ll > > building(N);
int main()
{
ios_base::sync_with_stdio(false);
cin >> n >> m;
rep(i,0,m)
{
cin >> pos[i] >> jump[i];
building[pos[i]].push_back(jump[i]);
}
rep(i,0,n)
d[i] = INF;
priority_queue < pi > pq;
pq.push(mp(0,pos[0]));
d[pos[0]] = 0;
while(!pq.empty())
{
pi cur = pq.top();
pq.pop();
if(-cur.first > d[cur.second])
continue;
rep(i,0,building[cur.second].size())
{
ll p = building[cur.second][i];
ll j = -1;
while(cur.second + p*j >= 0)
{
if(-cur.first - j < d[cur.second+p*j])
{
d[cur.second+p*j] = -cur.first-j;
pq.push(mp(-d[cur.second+p*j],cur.second+p*j));
}
j--;
}
j = 0;
while(cur.second + p*j < n)
{
if(-cur.first + j < d[cur.second+p*j])
{
d[cur.second+p*j] = -cur.first+j;
pq.push(mp(-d[cur.second+p*j],cur.second+p*j));
}
j++;
}
}
}
if(d[pos[1]] != INF)
cout << d[pos[1]] << endl;
else
cout << -1 << endl;
return 0;
}
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... |