#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define inf INT_MAX
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FAR(i, a, b) for (int i = (a); i >= (b); i--)
#define all(x) (x.begin(), x.end())
const int MOD = 1e9 + 7;
const int mx = 3e4 + 5;
using namespace std;
int d[mx], b[mx], p[mx];
bool vis[mx];
vector<int> v[mx];
int main()
{
int n, m, q = 0;
cin >> n >> m;
FOR(i, 0, mx)
d[i] = inf;
FOR(i, 0, m)
{
cin >> b[i] >> p[i];
v[b[i]].push_back(p[i]);
}
int idx = b[0];
d[idx] = 0;
while (!vis[b[1]] && idx != -1)
{
vis[idx] = 1;
for (auto it : v[idx])
{
for (int j = 1; idx + j * it < n; j++)
d[idx + j * it] = min(d[idx + j * it], d[idx] + j);
for (int j = 1; idx - j * it >= 0; j++)
d[idx - j * it] = min(d[idx - j * it], d[idx] + j);
}
idx = -1;
FOR(i, 0, n)
{
if (vis[i])
continue;
if (d[i] == inf)
continue;
if (idx == -1 || d[idx] > d[i])
idx = i;
}
}
if (d[b[1]] == inf)
d[b[1]] = -1;
cout << d[b[1]] << endl;
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:17:13: warning: unused variable 'q' [-Wunused-variable]
17 | int n, m, q = 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1104 KB |
Output is correct |
2 |
Correct |
1 ms |
1104 KB |
Output is correct |
3 |
Correct |
1 ms |
1104 KB |
Output is correct |
4 |
Correct |
2 ms |
1104 KB |
Output is correct |
5 |
Correct |
1 ms |
1104 KB |
Output is correct |
6 |
Correct |
1 ms |
1104 KB |
Output is correct |
7 |
Correct |
1 ms |
1148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1104 KB |
Output is correct |
2 |
Correct |
2 ms |
1104 KB |
Output is correct |
3 |
Correct |
1 ms |
1104 KB |
Output is correct |
4 |
Correct |
1 ms |
1104 KB |
Output is correct |
5 |
Correct |
2 ms |
1272 KB |
Output is correct |
6 |
Correct |
1 ms |
1104 KB |
Output is correct |
7 |
Correct |
1 ms |
1272 KB |
Output is correct |
8 |
Correct |
1 ms |
1104 KB |
Output is correct |
9 |
Correct |
2 ms |
1104 KB |
Output is correct |
10 |
Correct |
2 ms |
1104 KB |
Output is correct |
11 |
Correct |
2 ms |
1104 KB |
Output is correct |
12 |
Correct |
2 ms |
1104 KB |
Output is correct |
13 |
Correct |
2 ms |
1104 KB |
Output is correct |
14 |
Correct |
2 ms |
1104 KB |
Output is correct |
15 |
Correct |
2 ms |
1104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1104 KB |
Output is correct |
3 |
Correct |
2 ms |
1104 KB |
Output is correct |
4 |
Correct |
1 ms |
1104 KB |
Output is correct |
5 |
Correct |
1 ms |
1104 KB |
Output is correct |
6 |
Correct |
1 ms |
1104 KB |
Output is correct |
7 |
Correct |
1 ms |
1104 KB |
Output is correct |
8 |
Correct |
2 ms |
1104 KB |
Output is correct |
9 |
Correct |
1 ms |
1104 KB |
Output is correct |
10 |
Correct |
2 ms |
1104 KB |
Output is correct |
11 |
Correct |
2 ms |
1104 KB |
Output is correct |
12 |
Correct |
2 ms |
1104 KB |
Output is correct |
13 |
Correct |
2 ms |
1104 KB |
Output is correct |
14 |
Correct |
2 ms |
1104 KB |
Output is correct |
15 |
Correct |
2 ms |
1168 KB |
Output is correct |
16 |
Correct |
2 ms |
1104 KB |
Output is correct |
17 |
Correct |
3 ms |
1104 KB |
Output is correct |
18 |
Correct |
2 ms |
1104 KB |
Output is correct |
19 |
Correct |
1 ms |
1152 KB |
Output is correct |
20 |
Correct |
11 ms |
1360 KB |
Output is correct |
21 |
Correct |
2 ms |
1104 KB |
Output is correct |
22 |
Correct |
2 ms |
1272 KB |
Output is correct |
23 |
Correct |
5 ms |
1104 KB |
Output is correct |
24 |
Correct |
5 ms |
1276 KB |
Output is correct |
25 |
Correct |
3 ms |
1104 KB |
Output is correct |
26 |
Correct |
5 ms |
1104 KB |
Output is correct |
27 |
Correct |
7 ms |
1104 KB |
Output is correct |
28 |
Correct |
5 ms |
1360 KB |
Output is correct |
29 |
Correct |
8 ms |
1104 KB |
Output is correct |
30 |
Correct |
7 ms |
1272 KB |
Output is correct |
31 |
Correct |
8 ms |
1104 KB |
Output is correct |
32 |
Correct |
8 ms |
1104 KB |
Output is correct |
33 |
Correct |
8 ms |
1104 KB |
Output is correct |
34 |
Correct |
8 ms |
1104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1272 KB |
Output is correct |
2 |
Correct |
2 ms |
1152 KB |
Output is correct |
3 |
Correct |
1 ms |
1104 KB |
Output is correct |
4 |
Correct |
1 ms |
1104 KB |
Output is correct |
5 |
Correct |
1 ms |
1104 KB |
Output is correct |
6 |
Correct |
1 ms |
1104 KB |
Output is correct |
7 |
Correct |
2 ms |
1104 KB |
Output is correct |
8 |
Correct |
1 ms |
1104 KB |
Output is correct |
9 |
Correct |
1 ms |
1104 KB |
Output is correct |
10 |
Correct |
1 ms |
1104 KB |
Output is correct |
11 |
Correct |
2 ms |
1104 KB |
Output is correct |
12 |
Correct |
2 ms |
1104 KB |
Output is correct |
13 |
Correct |
3 ms |
1104 KB |
Output is correct |
14 |
Correct |
2 ms |
1104 KB |
Output is correct |
15 |
Correct |
2 ms |
1164 KB |
Output is correct |
16 |
Correct |
2 ms |
1104 KB |
Output is correct |
17 |
Correct |
3 ms |
1104 KB |
Output is correct |
18 |
Correct |
2 ms |
1104 KB |
Output is correct |
19 |
Correct |
2 ms |
1104 KB |
Output is correct |
20 |
Correct |
11 ms |
1360 KB |
Output is correct |
21 |
Correct |
2 ms |
1104 KB |
Output is correct |
22 |
Correct |
1 ms |
1104 KB |
Output is correct |
23 |
Correct |
6 ms |
1104 KB |
Output is correct |
24 |
Correct |
9 ms |
1104 KB |
Output is correct |
25 |
Correct |
4 ms |
1272 KB |
Output is correct |
26 |
Correct |
4 ms |
1104 KB |
Output is correct |
27 |
Correct |
7 ms |
1272 KB |
Output is correct |
28 |
Correct |
5 ms |
1164 KB |
Output is correct |
29 |
Correct |
8 ms |
1296 KB |
Output is correct |
30 |
Correct |
7 ms |
1104 KB |
Output is correct |
31 |
Correct |
7 ms |
1104 KB |
Output is correct |
32 |
Correct |
8 ms |
1104 KB |
Output is correct |
33 |
Correct |
8 ms |
1104 KB |
Output is correct |
34 |
Correct |
8 ms |
1104 KB |
Output is correct |
35 |
Correct |
12 ms |
1896 KB |
Output is correct |
36 |
Correct |
3 ms |
1512 KB |
Output is correct |
37 |
Correct |
12 ms |
1628 KB |
Output is correct |
38 |
Correct |
14 ms |
1884 KB |
Output is correct |
39 |
Correct |
15 ms |
2128 KB |
Output is correct |
40 |
Correct |
11 ms |
1996 KB |
Output is correct |
41 |
Correct |
14 ms |
1872 KB |
Output is correct |
42 |
Correct |
11 ms |
1872 KB |
Output is correct |
43 |
Correct |
51 ms |
1872 KB |
Output is correct |
44 |
Correct |
55 ms |
1908 KB |
Output is correct |
45 |
Correct |
19 ms |
1872 KB |
Output is correct |
46 |
Correct |
15 ms |
1872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1104 KB |
Output is correct |
2 |
Correct |
2 ms |
1104 KB |
Output is correct |
3 |
Correct |
1 ms |
1104 KB |
Output is correct |
4 |
Correct |
1 ms |
1104 KB |
Output is correct |
5 |
Correct |
2 ms |
1104 KB |
Output is correct |
6 |
Correct |
1 ms |
1152 KB |
Output is correct |
7 |
Correct |
1 ms |
1104 KB |
Output is correct |
8 |
Correct |
2 ms |
1104 KB |
Output is correct |
9 |
Correct |
1 ms |
1104 KB |
Output is correct |
10 |
Correct |
2 ms |
1116 KB |
Output is correct |
11 |
Correct |
2 ms |
1104 KB |
Output is correct |
12 |
Correct |
2 ms |
1104 KB |
Output is correct |
13 |
Correct |
2 ms |
1104 KB |
Output is correct |
14 |
Correct |
2 ms |
1104 KB |
Output is correct |
15 |
Correct |
3 ms |
1104 KB |
Output is correct |
16 |
Correct |
2 ms |
1104 KB |
Output is correct |
17 |
Correct |
3 ms |
1104 KB |
Output is correct |
18 |
Correct |
2 ms |
1104 KB |
Output is correct |
19 |
Correct |
1 ms |
1104 KB |
Output is correct |
20 |
Correct |
10 ms |
1364 KB |
Output is correct |
21 |
Correct |
2 ms |
1104 KB |
Output is correct |
22 |
Correct |
1 ms |
1148 KB |
Output is correct |
23 |
Correct |
4 ms |
1104 KB |
Output is correct |
24 |
Correct |
6 ms |
1104 KB |
Output is correct |
25 |
Correct |
3 ms |
1104 KB |
Output is correct |
26 |
Correct |
5 ms |
1272 KB |
Output is correct |
27 |
Correct |
7 ms |
1104 KB |
Output is correct |
28 |
Correct |
5 ms |
1360 KB |
Output is correct |
29 |
Correct |
8 ms |
1312 KB |
Output is correct |
30 |
Correct |
8 ms |
1360 KB |
Output is correct |
31 |
Correct |
8 ms |
1360 KB |
Output is correct |
32 |
Correct |
8 ms |
1104 KB |
Output is correct |
33 |
Correct |
8 ms |
1104 KB |
Output is correct |
34 |
Correct |
8 ms |
1104 KB |
Output is correct |
35 |
Correct |
13 ms |
1872 KB |
Output is correct |
36 |
Correct |
4 ms |
1360 KB |
Output is correct |
37 |
Correct |
11 ms |
1672 KB |
Output is correct |
38 |
Correct |
15 ms |
1872 KB |
Output is correct |
39 |
Correct |
11 ms |
2040 KB |
Output is correct |
40 |
Correct |
11 ms |
1872 KB |
Output is correct |
41 |
Correct |
12 ms |
1872 KB |
Output is correct |
42 |
Correct |
12 ms |
1872 KB |
Output is correct |
43 |
Correct |
51 ms |
1872 KB |
Output is correct |
44 |
Correct |
55 ms |
1872 KB |
Output is correct |
45 |
Correct |
16 ms |
1872 KB |
Output is correct |
46 |
Correct |
15 ms |
1872 KB |
Output is correct |
47 |
Correct |
134 ms |
1872 KB |
Output is correct |
48 |
Correct |
11 ms |
2128 KB |
Output is correct |
49 |
Correct |
11 ms |
2128 KB |
Output is correct |
50 |
Correct |
7 ms |
1872 KB |
Output is correct |
51 |
Execution timed out |
1053 ms |
2384 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |