# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
383367 | tjrwodnjs999 | Jakarta Skyscrapers (APIO15_skyscraper) | C++11 | 670 ms | 112748 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 ll long long
#define x first
#define y second
using namespace std;
int n,m,B[30005],P[30005],v[30005];
queue<pair<pair<int,int>,int>> q;
vector<int> vt[30005];
bitset<30005> bit[30005];
void f(int now,int p,int cost){
if(!v[now]){
v[now]=1;
for(int i:vt[now]){
if(!bit[now][i]){
bit[now][i]=1;
q.push({{now,i},cost});
}
}
}
if(!bit[now][p]){
bit[now][p]=1;
q.push({{now,p},cost});
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
scanf("%d%d",&B[i],&P[i]);
vt[B[i]].push_back(P[i]);
}
v[B[1]]=1;
for(int i:vt[B[1]]){
if(!bit[B[1]][i]){
bit[B[1]][i]=1;
q.push({{B[1],i},0});
}
}
while(!q.empty()){
int now=q.front().x.x,p=q.front().x.y,cost=q.front().y; q.pop();
if(now==B[2]) return !printf("%d",cost);
if(now-p>=0) f(now-p,p,cost+1);
if(now+p<n) f(now+p,p,cost+1);
}
printf("-1");
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... |