#include <bits/stdc++.h>
#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair
#define int long long
using namespace std;
typedef long long ll;
const int inf = (int)1e15 + 7;
const int N = (int)2e5 + 7;
int n,m;
int b[N],p[N];
int d[N];
vector <int> vec[N];
vector <pair<int,int> > g[N];
priority_queue<pair<int,int> > q;
bool check (int l,int r,int x) {
if (abs(r - l) % x == 0)
return true;
return false;
}
int f (int l,int r,int x) {
return (abs(r - l) / x);
}
main () {
cin >> n >> m;
for (int i = 1; i <= m; i ++) {
cin >> b[i] >> p[i];
b[i] ++;
vec[b[i]].pb(p[i]);
}
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= n; j ++) {
int mnn = inf;
if (i == j)
continue;
for (auto to : vec[i]) {
if (check(i,j,to))
mnn = min(mnn,f(i,j,to));
}
if (mnn != inf)
g[i].pb(mk(j,mnn));
}
}
for (int i = 1; i <= n; i ++)
d[i] = inf;
d[b[1]] = 0;
q.push({0,b[1]});
while (!q.empty()) {
int v = q.top().sc,cur = -q.top().fr;
q.pop();
if (cur > d[v])
continue;
if (b[2] == v) {
cout << d[v] << endl;
return 0;
}
for (auto to : g[v]) {
if (d[v] + to.sc < d[to.fr]) {
d[to.fr] = d[v] + to.sc;
q.push({-d[to.fr],to.fr});
}
}
}
if (d[b[2]] == inf)
puts("-1");
else
cout << d[b[2]] << endl;
}
Compilation message
skyscraper.cpp:33:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9720 KB |
Output is correct |
2 |
Correct |
9 ms |
9720 KB |
Output is correct |
3 |
Correct |
12 ms |
9760 KB |
Output is correct |
4 |
Correct |
9 ms |
9888 KB |
Output is correct |
5 |
Correct |
10 ms |
9944 KB |
Output is correct |
6 |
Correct |
10 ms |
9944 KB |
Output is correct |
7 |
Correct |
10 ms |
9996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9996 KB |
Output is correct |
2 |
Correct |
10 ms |
9996 KB |
Output is correct |
3 |
Correct |
11 ms |
9996 KB |
Output is correct |
4 |
Correct |
9 ms |
9996 KB |
Output is correct |
5 |
Correct |
9 ms |
9996 KB |
Output is correct |
6 |
Correct |
10 ms |
9996 KB |
Output is correct |
7 |
Correct |
11 ms |
9996 KB |
Output is correct |
8 |
Correct |
9 ms |
9996 KB |
Output is correct |
9 |
Correct |
9 ms |
10068 KB |
Output is correct |
10 |
Correct |
11 ms |
10068 KB |
Output is correct |
11 |
Correct |
18 ms |
10084 KB |
Output is correct |
12 |
Correct |
13 ms |
10084 KB |
Output is correct |
13 |
Correct |
14 ms |
10212 KB |
Output is correct |
14 |
Correct |
13 ms |
10212 KB |
Output is correct |
15 |
Correct |
14 ms |
10212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
10212 KB |
Output is correct |
2 |
Correct |
9 ms |
10212 KB |
Output is correct |
3 |
Correct |
11 ms |
10212 KB |
Output is correct |
4 |
Correct |
9 ms |
10212 KB |
Output is correct |
5 |
Correct |
9 ms |
10212 KB |
Output is correct |
6 |
Correct |
9 ms |
10212 KB |
Output is correct |
7 |
Correct |
10 ms |
10212 KB |
Output is correct |
8 |
Correct |
10 ms |
10212 KB |
Output is correct |
9 |
Correct |
9 ms |
10212 KB |
Output is correct |
10 |
Correct |
11 ms |
10212 KB |
Output is correct |
11 |
Correct |
14 ms |
10212 KB |
Output is correct |
12 |
Correct |
14 ms |
10212 KB |
Output is correct |
13 |
Correct |
17 ms |
10212 KB |
Output is correct |
14 |
Correct |
13 ms |
10212 KB |
Output is correct |
15 |
Correct |
13 ms |
10212 KB |
Output is correct |
16 |
Correct |
13 ms |
10212 KB |
Output is correct |
17 |
Correct |
31 ms |
10472 KB |
Output is correct |
18 |
Correct |
37 ms |
10472 KB |
Output is correct |
19 |
Correct |
37 ms |
10472 KB |
Output is correct |
20 |
Correct |
159 ms |
74236 KB |
Output is correct |
21 |
Correct |
20 ms |
74236 KB |
Output is correct |
22 |
Correct |
35 ms |
74236 KB |
Output is correct |
23 |
Correct |
35 ms |
74236 KB |
Output is correct |
24 |
Correct |
66 ms |
74236 KB |
Output is correct |
25 |
Correct |
74 ms |
74236 KB |
Output is correct |
26 |
Correct |
102 ms |
74236 KB |
Output is correct |
27 |
Correct |
64 ms |
74236 KB |
Output is correct |
28 |
Correct |
76 ms |
74236 KB |
Output is correct |
29 |
Correct |
35 ms |
74236 KB |
Output is correct |
30 |
Correct |
27 ms |
74236 KB |
Output is correct |
31 |
Correct |
41 ms |
74236 KB |
Output is correct |
32 |
Correct |
27 ms |
74236 KB |
Output is correct |
33 |
Correct |
70 ms |
74236 KB |
Output is correct |
34 |
Correct |
70 ms |
74236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
74236 KB |
Output is correct |
2 |
Correct |
10 ms |
74236 KB |
Output is correct |
3 |
Correct |
10 ms |
74236 KB |
Output is correct |
4 |
Correct |
9 ms |
74236 KB |
Output is correct |
5 |
Correct |
9 ms |
74236 KB |
Output is correct |
6 |
Correct |
10 ms |
74236 KB |
Output is correct |
7 |
Correct |
9 ms |
74236 KB |
Output is correct |
8 |
Correct |
9 ms |
74236 KB |
Output is correct |
9 |
Correct |
10 ms |
74236 KB |
Output is correct |
10 |
Correct |
10 ms |
74236 KB |
Output is correct |
11 |
Correct |
13 ms |
74236 KB |
Output is correct |
12 |
Correct |
13 ms |
74236 KB |
Output is correct |
13 |
Correct |
13 ms |
74236 KB |
Output is correct |
14 |
Correct |
14 ms |
74236 KB |
Output is correct |
15 |
Correct |
13 ms |
74236 KB |
Output is correct |
16 |
Correct |
16 ms |
74236 KB |
Output is correct |
17 |
Correct |
30 ms |
74236 KB |
Output is correct |
18 |
Correct |
39 ms |
74236 KB |
Output is correct |
19 |
Correct |
30 ms |
74236 KB |
Output is correct |
20 |
Correct |
154 ms |
74364 KB |
Output is correct |
21 |
Correct |
17 ms |
74364 KB |
Output is correct |
22 |
Correct |
35 ms |
74364 KB |
Output is correct |
23 |
Correct |
35 ms |
74364 KB |
Output is correct |
24 |
Correct |
67 ms |
74364 KB |
Output is correct |
25 |
Correct |
71 ms |
74364 KB |
Output is correct |
26 |
Correct |
63 ms |
74364 KB |
Output is correct |
27 |
Correct |
65 ms |
74364 KB |
Output is correct |
28 |
Correct |
74 ms |
74364 KB |
Output is correct |
29 |
Correct |
55 ms |
74364 KB |
Output is correct |
30 |
Correct |
20 ms |
74364 KB |
Output is correct |
31 |
Correct |
31 ms |
74364 KB |
Output is correct |
32 |
Correct |
28 ms |
74364 KB |
Output is correct |
33 |
Correct |
71 ms |
74364 KB |
Output is correct |
34 |
Correct |
70 ms |
74364 KB |
Output is correct |
35 |
Correct |
497 ms |
74364 KB |
Output is correct |
36 |
Correct |
86 ms |
74364 KB |
Output is correct |
37 |
Correct |
612 ms |
74364 KB |
Output is correct |
38 |
Correct |
959 ms |
74364 KB |
Output is correct |
39 |
Correct |
888 ms |
74364 KB |
Output is correct |
40 |
Execution timed out |
1074 ms |
74364 KB |
Time limit exceeded |
41 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
74364 KB |
Output is correct |
2 |
Correct |
10 ms |
74364 KB |
Output is correct |
3 |
Correct |
12 ms |
74364 KB |
Output is correct |
4 |
Correct |
11 ms |
74364 KB |
Output is correct |
5 |
Correct |
10 ms |
74364 KB |
Output is correct |
6 |
Correct |
9 ms |
74364 KB |
Output is correct |
7 |
Correct |
10 ms |
74364 KB |
Output is correct |
8 |
Correct |
10 ms |
74364 KB |
Output is correct |
9 |
Correct |
9 ms |
74364 KB |
Output is correct |
10 |
Correct |
10 ms |
74364 KB |
Output is correct |
11 |
Correct |
14 ms |
74364 KB |
Output is correct |
12 |
Correct |
14 ms |
74364 KB |
Output is correct |
13 |
Correct |
13 ms |
74364 KB |
Output is correct |
14 |
Correct |
17 ms |
74364 KB |
Output is correct |
15 |
Correct |
13 ms |
74364 KB |
Output is correct |
16 |
Correct |
16 ms |
74364 KB |
Output is correct |
17 |
Correct |
42 ms |
74364 KB |
Output is correct |
18 |
Correct |
55 ms |
74364 KB |
Output is correct |
19 |
Correct |
39 ms |
74364 KB |
Output is correct |
20 |
Correct |
206 ms |
74364 KB |
Output is correct |
21 |
Correct |
22 ms |
74364 KB |
Output is correct |
22 |
Correct |
33 ms |
74364 KB |
Output is correct |
23 |
Correct |
34 ms |
74364 KB |
Output is correct |
24 |
Correct |
81 ms |
74364 KB |
Output is correct |
25 |
Correct |
110 ms |
74364 KB |
Output is correct |
26 |
Correct |
66 ms |
74364 KB |
Output is correct |
27 |
Correct |
64 ms |
74364 KB |
Output is correct |
28 |
Correct |
83 ms |
74364 KB |
Output is correct |
29 |
Correct |
36 ms |
74364 KB |
Output is correct |
30 |
Correct |
23 ms |
74364 KB |
Output is correct |
31 |
Correct |
30 ms |
74364 KB |
Output is correct |
32 |
Correct |
28 ms |
74364 KB |
Output is correct |
33 |
Correct |
68 ms |
74364 KB |
Output is correct |
34 |
Correct |
69 ms |
74364 KB |
Output is correct |
35 |
Correct |
510 ms |
74364 KB |
Output is correct |
36 |
Correct |
93 ms |
74364 KB |
Output is correct |
37 |
Correct |
513 ms |
74364 KB |
Output is correct |
38 |
Correct |
804 ms |
74364 KB |
Output is correct |
39 |
Correct |
880 ms |
74364 KB |
Output is correct |
40 |
Correct |
947 ms |
74364 KB |
Output is correct |
41 |
Correct |
793 ms |
74364 KB |
Output is correct |
42 |
Correct |
768 ms |
74364 KB |
Output is correct |
43 |
Correct |
776 ms |
74364 KB |
Output is correct |
44 |
Correct |
896 ms |
75000 KB |
Output is correct |
45 |
Correct |
835 ms |
75000 KB |
Output is correct |
46 |
Correct |
790 ms |
75000 KB |
Output is correct |
47 |
Execution timed out |
1079 ms |
75000 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |