#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<int,int>P;
typedef long long ll;
int b[50000],t[50000];
int d[2200][2200];
vector<int>v[2200];
struct st{
int a,b,c;
};
bool operator<(st a,st b){
return a.c>b.c;
}
int main(){
int n,m;cin>>n>>m;
rep(i,m){
scanf("%d%d",&b[i],&t[i]);
v[b[i]].push_back(t[i]);
}
memset(d,0x3f,sizeof(d));
d[b[0]][0]=0;
priority_queue<st>que;
que.push({b[0],0,0});
while(!que.empty()){
st p=que.top();que.pop();
int c=d[p.a][p.b];
if(c!=p.c)continue;
if(p.b==0){
for(int i:v[p.a]){
if(d[p.a][i]>c){
d[p.a][i]=c;
que.push({p.a,i,c});
}
}
}
else{
int v;
if((v=p.a-p.b)>=0&&d[v][p.b]>c+1){
d[v][p.b]=c+1;
que.push({v,p.b,c+1});
}
if((v=p.a+p.b)<n&&d[v][p.b]>c+1){
d[v][p.b]=c+1;
que.push({v,p.b,c+1});
}
if(d[p.a][0]>c){
d[p.a][0]=c;
que.push({p.a,0,c});
}
}
}
int ans=*min_element(d[b[1]],d[b[1]]+2200);
if(ans==INF)puts("-1");
else cout<<ans<<endl;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&b[i],&t[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
19328 KB |
Output is correct |
2 |
Correct |
18 ms |
19456 KB |
Output is correct |
3 |
Correct |
18 ms |
19328 KB |
Output is correct |
4 |
Correct |
18 ms |
19320 KB |
Output is correct |
5 |
Correct |
21 ms |
19328 KB |
Output is correct |
6 |
Correct |
17 ms |
19328 KB |
Output is correct |
7 |
Correct |
17 ms |
19328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
19328 KB |
Output is correct |
2 |
Correct |
19 ms |
19328 KB |
Output is correct |
3 |
Correct |
19 ms |
19320 KB |
Output is correct |
4 |
Correct |
19 ms |
19456 KB |
Output is correct |
5 |
Correct |
17 ms |
19448 KB |
Output is correct |
6 |
Correct |
20 ms |
19328 KB |
Output is correct |
7 |
Correct |
18 ms |
19320 KB |
Output is correct |
8 |
Correct |
18 ms |
19328 KB |
Output is correct |
9 |
Correct |
17 ms |
19328 KB |
Output is correct |
10 |
Correct |
20 ms |
19328 KB |
Output is correct |
11 |
Correct |
18 ms |
19456 KB |
Output is correct |
12 |
Correct |
20 ms |
19320 KB |
Output is correct |
13 |
Correct |
16 ms |
19328 KB |
Output is correct |
14 |
Correct |
17 ms |
19456 KB |
Output is correct |
15 |
Correct |
19 ms |
19456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
19328 KB |
Output is correct |
2 |
Correct |
18 ms |
19328 KB |
Output is correct |
3 |
Correct |
19 ms |
19328 KB |
Output is correct |
4 |
Correct |
22 ms |
19328 KB |
Output is correct |
5 |
Correct |
17 ms |
19328 KB |
Output is correct |
6 |
Correct |
16 ms |
19328 KB |
Output is correct |
7 |
Correct |
17 ms |
19328 KB |
Output is correct |
8 |
Correct |
19 ms |
19328 KB |
Output is correct |
9 |
Correct |
20 ms |
19320 KB |
Output is correct |
10 |
Correct |
19 ms |
19328 KB |
Output is correct |
11 |
Correct |
19 ms |
19376 KB |
Output is correct |
12 |
Correct |
18 ms |
19328 KB |
Output is correct |
13 |
Correct |
18 ms |
19328 KB |
Output is correct |
14 |
Correct |
20 ms |
19456 KB |
Output is correct |
15 |
Correct |
18 ms |
19456 KB |
Output is correct |
16 |
Correct |
18 ms |
19320 KB |
Output is correct |
17 |
Correct |
21 ms |
19456 KB |
Output is correct |
18 |
Correct |
21 ms |
19356 KB |
Output is correct |
19 |
Correct |
20 ms |
19328 KB |
Output is correct |
20 |
Correct |
19 ms |
19448 KB |
Output is correct |
21 |
Correct |
20 ms |
19372 KB |
Output is correct |
22 |
Correct |
18 ms |
19300 KB |
Output is correct |
23 |
Correct |
22 ms |
19328 KB |
Output is correct |
24 |
Correct |
24 ms |
19328 KB |
Output is correct |
25 |
Correct |
21 ms |
19320 KB |
Output is correct |
26 |
Correct |
22 ms |
19328 KB |
Output is correct |
27 |
Correct |
21 ms |
19328 KB |
Output is correct |
28 |
Correct |
20 ms |
19456 KB |
Output is correct |
29 |
Correct |
26 ms |
19328 KB |
Output is correct |
30 |
Correct |
21 ms |
19328 KB |
Output is correct |
31 |
Correct |
21 ms |
19328 KB |
Output is correct |
32 |
Correct |
22 ms |
19328 KB |
Output is correct |
33 |
Correct |
31 ms |
19456 KB |
Output is correct |
34 |
Correct |
28 ms |
19448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
19328 KB |
Output is correct |
2 |
Correct |
18 ms |
19384 KB |
Output is correct |
3 |
Correct |
19 ms |
19456 KB |
Output is correct |
4 |
Correct |
17 ms |
19328 KB |
Output is correct |
5 |
Correct |
17 ms |
19328 KB |
Output is correct |
6 |
Correct |
18 ms |
19328 KB |
Output is correct |
7 |
Correct |
17 ms |
19328 KB |
Output is correct |
8 |
Correct |
17 ms |
19328 KB |
Output is correct |
9 |
Correct |
17 ms |
19328 KB |
Output is correct |
10 |
Correct |
19 ms |
19328 KB |
Output is correct |
11 |
Correct |
18 ms |
19456 KB |
Output is correct |
12 |
Correct |
17 ms |
19192 KB |
Output is correct |
13 |
Correct |
17 ms |
19328 KB |
Output is correct |
14 |
Correct |
19 ms |
19456 KB |
Output is correct |
15 |
Correct |
25 ms |
19456 KB |
Output is correct |
16 |
Correct |
19 ms |
19328 KB |
Output is correct |
17 |
Correct |
20 ms |
19456 KB |
Output is correct |
18 |
Correct |
18 ms |
19328 KB |
Output is correct |
19 |
Correct |
18 ms |
19328 KB |
Output is correct |
20 |
Correct |
19 ms |
19456 KB |
Output is correct |
21 |
Correct |
18 ms |
19328 KB |
Output is correct |
22 |
Correct |
20 ms |
19328 KB |
Output is correct |
23 |
Correct |
20 ms |
19328 KB |
Output is correct |
24 |
Correct |
23 ms |
19456 KB |
Output is correct |
25 |
Correct |
19 ms |
19428 KB |
Output is correct |
26 |
Correct |
19 ms |
19328 KB |
Output is correct |
27 |
Correct |
21 ms |
19448 KB |
Output is correct |
28 |
Correct |
21 ms |
19456 KB |
Output is correct |
29 |
Correct |
23 ms |
19328 KB |
Output is correct |
30 |
Correct |
19 ms |
19328 KB |
Output is correct |
31 |
Correct |
20 ms |
19328 KB |
Output is correct |
32 |
Correct |
21 ms |
19328 KB |
Output is correct |
33 |
Correct |
31 ms |
19448 KB |
Output is correct |
34 |
Correct |
26 ms |
19456 KB |
Output is correct |
35 |
Correct |
41 ms |
20088 KB |
Output is correct |
36 |
Correct |
21 ms |
19456 KB |
Output is correct |
37 |
Correct |
62 ms |
20224 KB |
Output is correct |
38 |
Correct |
57 ms |
20276 KB |
Output is correct |
39 |
Correct |
69 ms |
20280 KB |
Output is correct |
40 |
Correct |
73 ms |
20280 KB |
Output is correct |
41 |
Correct |
55 ms |
20416 KB |
Output is correct |
42 |
Correct |
23 ms |
19840 KB |
Output is correct |
43 |
Correct |
22 ms |
19832 KB |
Output is correct |
44 |
Correct |
25 ms |
19840 KB |
Output is correct |
45 |
Correct |
78 ms |
20280 KB |
Output is correct |
46 |
Correct |
69 ms |
20408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
19328 KB |
Output is correct |
2 |
Correct |
17 ms |
19328 KB |
Output is correct |
3 |
Correct |
18 ms |
19328 KB |
Output is correct |
4 |
Correct |
20 ms |
19328 KB |
Output is correct |
5 |
Correct |
20 ms |
19328 KB |
Output is correct |
6 |
Correct |
20 ms |
19328 KB |
Output is correct |
7 |
Correct |
18 ms |
19320 KB |
Output is correct |
8 |
Correct |
19 ms |
19328 KB |
Output is correct |
9 |
Correct |
17 ms |
19328 KB |
Output is correct |
10 |
Correct |
20 ms |
19328 KB |
Output is correct |
11 |
Correct |
20 ms |
19328 KB |
Output is correct |
12 |
Correct |
18 ms |
19328 KB |
Output is correct |
13 |
Correct |
20 ms |
19456 KB |
Output is correct |
14 |
Correct |
22 ms |
19456 KB |
Output is correct |
15 |
Correct |
22 ms |
19428 KB |
Output is correct |
16 |
Correct |
17 ms |
19328 KB |
Output is correct |
17 |
Correct |
21 ms |
19464 KB |
Output is correct |
18 |
Correct |
18 ms |
19328 KB |
Output is correct |
19 |
Correct |
18 ms |
19328 KB |
Output is correct |
20 |
Correct |
18 ms |
19456 KB |
Output is correct |
21 |
Correct |
18 ms |
19328 KB |
Output is correct |
22 |
Correct |
21 ms |
19328 KB |
Output is correct |
23 |
Correct |
22 ms |
19328 KB |
Output is correct |
24 |
Correct |
26 ms |
19420 KB |
Output is correct |
25 |
Correct |
21 ms |
19456 KB |
Output is correct |
26 |
Correct |
20 ms |
19328 KB |
Output is correct |
27 |
Correct |
18 ms |
19328 KB |
Output is correct |
28 |
Correct |
23 ms |
19328 KB |
Output is correct |
29 |
Correct |
22 ms |
19356 KB |
Output is correct |
30 |
Correct |
20 ms |
19328 KB |
Output is correct |
31 |
Correct |
22 ms |
19328 KB |
Output is correct |
32 |
Correct |
21 ms |
19328 KB |
Output is correct |
33 |
Correct |
30 ms |
19328 KB |
Output is correct |
34 |
Correct |
31 ms |
19448 KB |
Output is correct |
35 |
Correct |
45 ms |
20116 KB |
Output is correct |
36 |
Correct |
23 ms |
19456 KB |
Output is correct |
37 |
Correct |
59 ms |
20152 KB |
Output is correct |
38 |
Correct |
59 ms |
20408 KB |
Output is correct |
39 |
Correct |
58 ms |
20288 KB |
Output is correct |
40 |
Correct |
60 ms |
20280 KB |
Output is correct |
41 |
Correct |
56 ms |
20460 KB |
Output is correct |
42 |
Correct |
24 ms |
19736 KB |
Output is correct |
43 |
Correct |
24 ms |
19840 KB |
Output is correct |
44 |
Correct |
23 ms |
19804 KB |
Output is correct |
45 |
Correct |
77 ms |
20280 KB |
Output is correct |
46 |
Correct |
82 ms |
20416 KB |
Output is correct |
47 |
Runtime error |
53 ms |
39672 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
48 |
Halted |
0 ms |
0 KB |
- |