#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const N=3e4+5;
int const inf=1e9+7;
vector<int> sky[N];
int pw[N];
int pos[N];
set<pair<int,int>> vis;
int main(){
int n,m;
cin>>n>>m;
for (int i = 0; i < m; ++i){
cin>>pos[i]>>pw[i];
sky[pos[i]].push_back(pw[i]);
}
int tar=pos[1];
vector<int> in;
in.push_back(pos[0]);
vis.insert({pos[0],pw[0]});
int cur=0;
while(in.size()){
vector<pair<int,int>> upd;
for(int c:in){
// cout<<"sky := "<<c<<endl;
if(c==tar){
cout<<cur<<endl;
return 0;
}
for(int p:sky[c]){
// cout<<p<<' ';
if(c+p<n)
upd.push_back({c+p,p});
if(c-p>=0)
upd.push_back({c-p,p});
}
// cout<<endl;
sky[c].clear();
}
in.clear();
// cout<<"Upd"<<endl;
for(auto [s,p]:upd){
if(vis.find({s,p})!=vis.end())
continue;
// cout<<s<<' '<<p<<endl;
vis.insert({s,p});
sky[s].push_back(p);
in.push_back(s);
}
cur++;
// cout<<"next"<<endl;
}
cout<<-1<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
0 ms |
1128 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
0 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
0 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
0 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1112 KB |
Output is correct |
5 |
Correct |
1 ms |
1368 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1112 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
2 ms |
1392 KB |
Output is correct |
13 |
Correct |
1 ms |
1112 KB |
Output is correct |
14 |
Correct |
4 ms |
1368 KB |
Output is correct |
15 |
Correct |
2 ms |
1112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1112 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1152 KB |
Output is correct |
7 |
Correct |
1 ms |
1112 KB |
Output is correct |
8 |
Correct |
0 ms |
1116 KB |
Output is correct |
9 |
Correct |
0 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1112 KB |
Output is correct |
14 |
Correct |
3 ms |
1368 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1152 KB |
Output is correct |
17 |
Correct |
2 ms |
1372 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
1 ms |
1116 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1112 KB |
Output is correct |
23 |
Correct |
2 ms |
1372 KB |
Output is correct |
24 |
Correct |
3 ms |
1460 KB |
Output is correct |
25 |
Correct |
1 ms |
1116 KB |
Output is correct |
26 |
Correct |
2 ms |
1352 KB |
Output is correct |
27 |
Correct |
2 ms |
1352 KB |
Output is correct |
28 |
Correct |
8 ms |
2132 KB |
Output is correct |
29 |
Correct |
20 ms |
3940 KB |
Output is correct |
30 |
Correct |
6 ms |
1884 KB |
Output is correct |
31 |
Correct |
12 ms |
2648 KB |
Output is correct |
32 |
Correct |
8 ms |
2140 KB |
Output is correct |
33 |
Correct |
45 ms |
6660 KB |
Output is correct |
34 |
Correct |
21 ms |
4188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
0 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1368 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
0 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1112 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
14 |
Correct |
3 ms |
1372 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
2 ms |
1372 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
2 ms |
1116 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
3 ms |
1372 KB |
Output is correct |
24 |
Correct |
3 ms |
1504 KB |
Output is correct |
25 |
Correct |
1 ms |
1116 KB |
Output is correct |
26 |
Correct |
2 ms |
1368 KB |
Output is correct |
27 |
Correct |
2 ms |
1372 KB |
Output is correct |
28 |
Correct |
7 ms |
2140 KB |
Output is correct |
29 |
Correct |
20 ms |
3876 KB |
Output is correct |
30 |
Correct |
5 ms |
1884 KB |
Output is correct |
31 |
Correct |
11 ms |
2692 KB |
Output is correct |
32 |
Correct |
10 ms |
2140 KB |
Output is correct |
33 |
Correct |
50 ms |
6716 KB |
Output is correct |
34 |
Correct |
21 ms |
4184 KB |
Output is correct |
35 |
Correct |
12 ms |
2796 KB |
Output is correct |
36 |
Correct |
2 ms |
1112 KB |
Output is correct |
37 |
Correct |
7 ms |
2136 KB |
Output is correct |
38 |
Correct |
11 ms |
2560 KB |
Output is correct |
39 |
Correct |
9 ms |
1856 KB |
Output is correct |
40 |
Correct |
9 ms |
1880 KB |
Output is correct |
41 |
Correct |
10 ms |
1884 KB |
Output is correct |
42 |
Correct |
8 ms |
1708 KB |
Output is correct |
43 |
Correct |
8 ms |
1880 KB |
Output is correct |
44 |
Correct |
9 ms |
2264 KB |
Output is correct |
45 |
Correct |
242 ms |
25072 KB |
Output is correct |
46 |
Correct |
118 ms |
15916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
0 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
0 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1152 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
14 |
Correct |
3 ms |
1372 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
2 ms |
1340 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
1 ms |
1116 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
2 ms |
1116 KB |
Output is correct |
23 |
Correct |
3 ms |
1416 KB |
Output is correct |
24 |
Correct |
5 ms |
1368 KB |
Output is correct |
25 |
Correct |
2 ms |
1116 KB |
Output is correct |
26 |
Correct |
2 ms |
1372 KB |
Output is correct |
27 |
Correct |
2 ms |
1372 KB |
Output is correct |
28 |
Correct |
8 ms |
1916 KB |
Output is correct |
29 |
Correct |
22 ms |
3976 KB |
Output is correct |
30 |
Correct |
6 ms |
1884 KB |
Output is correct |
31 |
Correct |
16 ms |
2568 KB |
Output is correct |
32 |
Correct |
9 ms |
2140 KB |
Output is correct |
33 |
Correct |
46 ms |
6804 KB |
Output is correct |
34 |
Correct |
19 ms |
4188 KB |
Output is correct |
35 |
Correct |
12 ms |
3024 KB |
Output is correct |
36 |
Correct |
2 ms |
1116 KB |
Output is correct |
37 |
Correct |
7 ms |
2160 KB |
Output is correct |
38 |
Correct |
11 ms |
2528 KB |
Output is correct |
39 |
Correct |
9 ms |
1884 KB |
Output is correct |
40 |
Correct |
9 ms |
1760 KB |
Output is correct |
41 |
Correct |
10 ms |
1884 KB |
Output is correct |
42 |
Correct |
10 ms |
2140 KB |
Output is correct |
43 |
Correct |
8 ms |
1884 KB |
Output is correct |
44 |
Correct |
9 ms |
2264 KB |
Output is correct |
45 |
Correct |
212 ms |
24996 KB |
Output is correct |
46 |
Correct |
148 ms |
15800 KB |
Output is correct |
47 |
Correct |
11 ms |
2396 KB |
Output is correct |
48 |
Correct |
8 ms |
2008 KB |
Output is correct |
49 |
Correct |
9 ms |
1804 KB |
Output is correct |
50 |
Correct |
6 ms |
1624 KB |
Output is correct |
51 |
Correct |
28 ms |
4684 KB |
Output is correct |
52 |
Correct |
33 ms |
4956 KB |
Output is correct |
53 |
Correct |
19 ms |
2384 KB |
Output is correct |
54 |
Correct |
4 ms |
2140 KB |
Output is correct |
55 |
Correct |
7 ms |
2844 KB |
Output is correct |
56 |
Correct |
20 ms |
3944 KB |
Output is correct |
57 |
Correct |
2 ms |
1116 KB |
Output is correct |
58 |
Correct |
26 ms |
5536 KB |
Output is correct |
59 |
Correct |
25 ms |
5460 KB |
Output is correct |
60 |
Correct |
25 ms |
5076 KB |
Output is correct |
61 |
Correct |
24 ms |
4956 KB |
Output is correct |
62 |
Correct |
245 ms |
22716 KB |
Output is correct |
63 |
Execution timed out |
1068 ms |
77576 KB |
Time limit exceeded |
64 |
Halted |
0 ms |
0 KB |
- |