/**
* author: AgentPengin ( Độc cô cầu bại )
* created: 23.12.2022 10:08:02
* too lazy to update time
**/
#include<bits/stdc++.h>
#define EL '\n'
#define fi first
#define se second
#define NAME "TASK"
#define ll long long
#define lcm(a,b) (a/gcd(a,b))*b
#define db(val) "["#val" = " << (val) << "] "
#define bend(v) (v).begin(),(v).end()
#define sz(v) (int)(v).size()
#define ex exit(0)
#define visit __visit
using namespace std;
const ll mod = 1e9 + 7;
const int inf = 0x1FFFFFFF;
const int MAXN = 30005;
int n,m,pw[MAXN],pos[MAXN];
vector<int> adj[MAXN];
bitset<MAXN> visit[MAXN];
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
if (ifstream(NAME".inp")) {
freopen(NAME".inp","r",stdin);
freopen(NAME".out","w",stdout);
}
cin >> n >> m;
for (int i = 1;i <= m;i++) {
cin >> pos[i] >> pw[i];
adj[pos[i]].push_back(pw[i]);
}
queue<tuple<int,int,int>> q;
q.push({pos[1],pw[1],0});
int ans = -1;
while(!q.empty()) {
int u,p,d;
tie(u,p,d) = q.front();
q.pop();
if (u == pos[2]) {
ans = d;
break;
}
if (u - p >= 0 && !visit[u - p][p]) {
visit[u - p][p] = 1;
q.push({u - p,p, d + 1});
}
if (u + p < n && !visit[u + p][p]) {
visit[u + p][p] = 1;
q.push({u + p,p,d + 1});
}
for (int p : adj[u]) {
visit[u][p] = 1;
if (u - p >= 0 && !visit[u - p][p]) {
visit[u - p][p] = 1;
q.push({u - p,p,d + 1});
}
if (u + p < n && !visit[u + p][p]) {
visit[u + p][p] = 1;
q.push({u + p,p,d + 1});
}
}
}
cout << ans;
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
// agent pengin wants to take apio (with anya-san)
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen(NAME".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | freopen(NAME".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2904 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2784 KB |
Output is correct |
14 |
Correct |
1 ms |
2908 KB |
Output is correct |
15 |
Correct |
1 ms |
2732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2404 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2904 KB |
Output is correct |
11 |
Correct |
1 ms |
2740 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2908 KB |
Output is correct |
14 |
Correct |
1 ms |
2788 KB |
Output is correct |
15 |
Correct |
1 ms |
2920 KB |
Output is correct |
16 |
Correct |
1 ms |
4440 KB |
Output is correct |
17 |
Correct |
2 ms |
5212 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
4 ms |
9900 KB |
Output is correct |
21 |
Correct |
1 ms |
4448 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
3 ms |
8180 KB |
Output is correct |
24 |
Correct |
3 ms |
9248 KB |
Output is correct |
25 |
Correct |
2 ms |
3812 KB |
Output is correct |
26 |
Correct |
3 ms |
8796 KB |
Output is correct |
27 |
Correct |
3 ms |
9048 KB |
Output is correct |
28 |
Correct |
4 ms |
9820 KB |
Output is correct |
29 |
Correct |
4 ms |
9820 KB |
Output is correct |
30 |
Correct |
4 ms |
9692 KB |
Output is correct |
31 |
Correct |
4 ms |
9816 KB |
Output is correct |
32 |
Correct |
4 ms |
9820 KB |
Output is correct |
33 |
Correct |
5 ms |
9828 KB |
Output is correct |
34 |
Correct |
5 ms |
9692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2908 KB |
Output is correct |
14 |
Correct |
1 ms |
2908 KB |
Output is correct |
15 |
Correct |
1 ms |
2908 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
5212 KB |
Output is correct |
18 |
Correct |
1 ms |
4576 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
4 ms |
9820 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4452 KB |
Output is correct |
23 |
Correct |
3 ms |
8028 KB |
Output is correct |
24 |
Correct |
3 ms |
9052 KB |
Output is correct |
25 |
Correct |
2 ms |
3932 KB |
Output is correct |
26 |
Correct |
3 ms |
8796 KB |
Output is correct |
27 |
Correct |
3 ms |
9052 KB |
Output is correct |
28 |
Correct |
3 ms |
9820 KB |
Output is correct |
29 |
Correct |
4 ms |
9820 KB |
Output is correct |
30 |
Correct |
4 ms |
9696 KB |
Output is correct |
31 |
Correct |
4 ms |
9820 KB |
Output is correct |
32 |
Correct |
4 ms |
9820 KB |
Output is correct |
33 |
Correct |
5 ms |
9820 KB |
Output is correct |
34 |
Correct |
5 ms |
9820 KB |
Output is correct |
35 |
Correct |
7 ms |
9580 KB |
Output is correct |
36 |
Correct |
2 ms |
5468 KB |
Output is correct |
37 |
Correct |
6 ms |
10080 KB |
Output is correct |
38 |
Correct |
9 ms |
11616 KB |
Output is correct |
39 |
Correct |
5 ms |
5472 KB |
Output is correct |
40 |
Correct |
6 ms |
5724 KB |
Output is correct |
41 |
Correct |
8 ms |
9828 KB |
Output is correct |
42 |
Correct |
7 ms |
9284 KB |
Output is correct |
43 |
Correct |
6 ms |
9708 KB |
Output is correct |
44 |
Correct |
6 ms |
10196 KB |
Output is correct |
45 |
Correct |
18 ms |
10600 KB |
Output is correct |
46 |
Correct |
14 ms |
10596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2400 KB |
Output is correct |
5 |
Correct |
1 ms |
2404 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2404 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2404 KB |
Output is correct |
10 |
Correct |
1 ms |
2772 KB |
Output is correct |
11 |
Correct |
1 ms |
2660 KB |
Output is correct |
12 |
Correct |
1 ms |
2660 KB |
Output is correct |
13 |
Correct |
1 ms |
2816 KB |
Output is correct |
14 |
Correct |
1 ms |
2916 KB |
Output is correct |
15 |
Correct |
1 ms |
2796 KB |
Output is correct |
16 |
Correct |
1 ms |
4456 KB |
Output is correct |
17 |
Correct |
2 ms |
5124 KB |
Output is correct |
18 |
Correct |
1 ms |
4456 KB |
Output is correct |
19 |
Correct |
1 ms |
2408 KB |
Output is correct |
20 |
Correct |
4 ms |
9832 KB |
Output is correct |
21 |
Correct |
1 ms |
4456 KB |
Output is correct |
22 |
Correct |
1 ms |
4544 KB |
Output is correct |
23 |
Correct |
2 ms |
8040 KB |
Output is correct |
24 |
Correct |
3 ms |
8972 KB |
Output is correct |
25 |
Correct |
1 ms |
3932 KB |
Output is correct |
26 |
Correct |
3 ms |
8796 KB |
Output is correct |
27 |
Correct |
4 ms |
9140 KB |
Output is correct |
28 |
Correct |
3 ms |
9820 KB |
Output is correct |
29 |
Correct |
4 ms |
9816 KB |
Output is correct |
30 |
Correct |
4 ms |
9820 KB |
Output is correct |
31 |
Correct |
4 ms |
9820 KB |
Output is correct |
32 |
Correct |
4 ms |
9820 KB |
Output is correct |
33 |
Correct |
5 ms |
9820 KB |
Output is correct |
34 |
Correct |
5 ms |
9760 KB |
Output is correct |
35 |
Correct |
7 ms |
9564 KB |
Output is correct |
36 |
Correct |
2 ms |
5468 KB |
Output is correct |
37 |
Correct |
7 ms |
10100 KB |
Output is correct |
38 |
Correct |
8 ms |
11612 KB |
Output is correct |
39 |
Correct |
5 ms |
5468 KB |
Output is correct |
40 |
Correct |
6 ms |
5724 KB |
Output is correct |
41 |
Correct |
8 ms |
9792 KB |
Output is correct |
42 |
Correct |
6 ms |
9308 KB |
Output is correct |
43 |
Correct |
6 ms |
9564 KB |
Output is correct |
44 |
Correct |
7 ms |
10308 KB |
Output is correct |
45 |
Correct |
18 ms |
10588 KB |
Output is correct |
46 |
Correct |
15 ms |
10724 KB |
Output is correct |
47 |
Correct |
18 ms |
33628 KB |
Output is correct |
48 |
Correct |
5 ms |
5212 KB |
Output is correct |
49 |
Correct |
4 ms |
5096 KB |
Output is correct |
50 |
Correct |
4 ms |
4956 KB |
Output is correct |
51 |
Correct |
49 ms |
87380 KB |
Output is correct |
52 |
Correct |
48 ms |
94032 KB |
Output is correct |
53 |
Correct |
12 ms |
19292 KB |
Output is correct |
54 |
Correct |
25 ms |
62036 KB |
Output is correct |
55 |
Correct |
33 ms |
78420 KB |
Output is correct |
56 |
Correct |
50 ms |
112468 KB |
Output is correct |
57 |
Correct |
2 ms |
4184 KB |
Output is correct |
58 |
Correct |
55 ms |
112380 KB |
Output is correct |
59 |
Correct |
47 ms |
104276 KB |
Output is correct |
60 |
Correct |
47 ms |
104428 KB |
Output is correct |
61 |
Correct |
45 ms |
99152 KB |
Output is correct |
62 |
Correct |
87 ms |
112720 KB |
Output is correct |
63 |
Correct |
119 ms |
112428 KB |
Output is correct |
64 |
Correct |
121 ms |
111956 KB |
Output is correct |
65 |
Correct |
160 ms |
112272 KB |
Output is correct |
66 |
Correct |
261 ms |
112464 KB |
Output is correct |
67 |
Correct |
159 ms |
112244 KB |
Output is correct |