#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define For(i, a, b) for(int i=a; i<b; i++)
#define ffi For(i, 0, N)
#define ffj For(j, 0, M)
#define ffa ffi ffj
#define w cout
#define e "\n"
#define s <<" "<<
#define pb push_back
#define mp make_pair
#define a first
#define b second
/// 500,000,000
const int MAXN = 30000, INF = 1000000000000000000;
/// Global Variables
int N, M, dist[MAXN], B[MAXN], P[MAXN];
bool vis[MAXN];
vector<int> dogs[MAXN];
priority_queue<pair<int, int> > next1; /// (-dist, loc)
void go(int loc) {
vis[loc] = true;
For (i, 0, dogs[loc].size()) {
int x = dogs[loc][i];
for (int j=loc+P[x], add = 1; j<N; j+= P[x], add++) {
dist[j] = min(dist[j], dist[loc]+add);
next1.push(mp(-dist[j], j));
}
for (int j=loc-P[x], add = 1; j>= 0; j-= P[x], add++) {
dist[j] = min(dist[j], dist[loc]+add);
next1.push(mp(-dist[j], j));
}
}
}
main() {
//ifstream cin("test.in");
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> M;
ffi dist[i] = INF;
ffj {
cin >> B[j] >> P[j];
dogs[B[j]].pb(j);
}
next1.push(mp(0, B[0]));
dist[B[0]] = 0;
while (!next1.empty()) {
int i = next1.top().b; next1.pop();
if (!vis[i]) go(i);
}
if (dist[B[1]] == INF) w<< -1<<e;
else w<< dist[B[1]]<<e;
}
Compilation message
skyscraper.cpp: In function 'void go(ll)':
skyscraper.cpp:5:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define For(i, a, b) for(int i=a; i<b; i++)
skyscraper.cpp:26:10:
For (i, 0, dogs[loc].size()) {
~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:26:5: note: in expansion of macro 'For'
For (i, 0, dogs[loc].size()) {
^~~
skyscraper.cpp: At global scope:
skyscraper.cpp:39:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1016 KB |
Output is correct |
2 |
Correct |
2 ms |
1124 KB |
Output is correct |
3 |
Correct |
2 ms |
1176 KB |
Output is correct |
4 |
Correct |
2 ms |
1216 KB |
Output is correct |
5 |
Correct |
3 ms |
1216 KB |
Output is correct |
6 |
Correct |
2 ms |
1216 KB |
Output is correct |
7 |
Correct |
2 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1280 KB |
Output is correct |
2 |
Correct |
2 ms |
1312 KB |
Output is correct |
3 |
Correct |
3 ms |
1312 KB |
Output is correct |
4 |
Correct |
3 ms |
1312 KB |
Output is correct |
5 |
Correct |
2 ms |
1312 KB |
Output is correct |
6 |
Correct |
3 ms |
1312 KB |
Output is correct |
7 |
Correct |
2 ms |
1312 KB |
Output is correct |
8 |
Correct |
3 ms |
1312 KB |
Output is correct |
9 |
Correct |
7 ms |
1312 KB |
Output is correct |
10 |
Correct |
3 ms |
1312 KB |
Output is correct |
11 |
Correct |
4 ms |
1512 KB |
Output is correct |
12 |
Correct |
50 ms |
5612 KB |
Output is correct |
13 |
Correct |
44 ms |
5612 KB |
Output is correct |
14 |
Correct |
4 ms |
5612 KB |
Output is correct |
15 |
Correct |
4 ms |
5612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5612 KB |
Output is correct |
2 |
Correct |
2 ms |
5612 KB |
Output is correct |
3 |
Correct |
2 ms |
5612 KB |
Output is correct |
4 |
Correct |
2 ms |
5612 KB |
Output is correct |
5 |
Correct |
2 ms |
5612 KB |
Output is correct |
6 |
Correct |
2 ms |
5612 KB |
Output is correct |
7 |
Correct |
2 ms |
5612 KB |
Output is correct |
8 |
Correct |
2 ms |
5612 KB |
Output is correct |
9 |
Correct |
2 ms |
5612 KB |
Output is correct |
10 |
Correct |
2 ms |
5612 KB |
Output is correct |
11 |
Correct |
4 ms |
5612 KB |
Output is correct |
12 |
Correct |
55 ms |
5632 KB |
Output is correct |
13 |
Correct |
44 ms |
5632 KB |
Output is correct |
14 |
Correct |
4 ms |
5632 KB |
Output is correct |
15 |
Correct |
5 ms |
5632 KB |
Output is correct |
16 |
Correct |
2 ms |
5632 KB |
Output is correct |
17 |
Correct |
7 ms |
5632 KB |
Output is correct |
18 |
Correct |
3 ms |
5632 KB |
Output is correct |
19 |
Correct |
4 ms |
5632 KB |
Output is correct |
20 |
Correct |
844 ms |
18072 KB |
Output is correct |
21 |
Correct |
4 ms |
18072 KB |
Output is correct |
22 |
Correct |
4 ms |
18072 KB |
Output is correct |
23 |
Correct |
4 ms |
18072 KB |
Output is correct |
24 |
Correct |
6 ms |
18072 KB |
Output is correct |
25 |
Correct |
5 ms |
18072 KB |
Output is correct |
26 |
Execution timed out |
1090 ms |
67420 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
67420 KB |
Output is correct |
2 |
Correct |
3 ms |
67420 KB |
Output is correct |
3 |
Correct |
3 ms |
67420 KB |
Output is correct |
4 |
Correct |
3 ms |
67420 KB |
Output is correct |
5 |
Correct |
3 ms |
67420 KB |
Output is correct |
6 |
Correct |
3 ms |
67420 KB |
Output is correct |
7 |
Correct |
3 ms |
67420 KB |
Output is correct |
8 |
Correct |
3 ms |
67420 KB |
Output is correct |
9 |
Correct |
3 ms |
67420 KB |
Output is correct |
10 |
Correct |
20 ms |
67420 KB |
Output is correct |
11 |
Correct |
5 ms |
67420 KB |
Output is correct |
12 |
Correct |
56 ms |
67420 KB |
Output is correct |
13 |
Correct |
47 ms |
67420 KB |
Output is correct |
14 |
Correct |
4 ms |
67420 KB |
Output is correct |
15 |
Correct |
4 ms |
67420 KB |
Output is correct |
16 |
Correct |
3 ms |
67420 KB |
Output is correct |
17 |
Correct |
7 ms |
67420 KB |
Output is correct |
18 |
Correct |
4 ms |
67420 KB |
Output is correct |
19 |
Correct |
3 ms |
67420 KB |
Output is correct |
20 |
Correct |
977 ms |
67420 KB |
Output is correct |
21 |
Correct |
4 ms |
67420 KB |
Output is correct |
22 |
Correct |
3 ms |
67420 KB |
Output is correct |
23 |
Correct |
3 ms |
67420 KB |
Output is correct |
24 |
Correct |
5 ms |
67420 KB |
Output is correct |
25 |
Correct |
8 ms |
67420 KB |
Output is correct |
26 |
Execution timed out |
1089 ms |
67624 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
67624 KB |
Output is correct |
2 |
Correct |
3 ms |
67624 KB |
Output is correct |
3 |
Correct |
3 ms |
67624 KB |
Output is correct |
4 |
Correct |
2 ms |
67624 KB |
Output is correct |
5 |
Correct |
3 ms |
67624 KB |
Output is correct |
6 |
Correct |
3 ms |
67624 KB |
Output is correct |
7 |
Correct |
3 ms |
67624 KB |
Output is correct |
8 |
Correct |
3 ms |
67624 KB |
Output is correct |
9 |
Correct |
3 ms |
67624 KB |
Output is correct |
10 |
Correct |
2 ms |
67624 KB |
Output is correct |
11 |
Correct |
4 ms |
67624 KB |
Output is correct |
12 |
Correct |
51 ms |
67624 KB |
Output is correct |
13 |
Correct |
53 ms |
67624 KB |
Output is correct |
14 |
Correct |
8 ms |
67624 KB |
Output is correct |
15 |
Correct |
4 ms |
67624 KB |
Output is correct |
16 |
Correct |
7 ms |
67624 KB |
Output is correct |
17 |
Correct |
7 ms |
67624 KB |
Output is correct |
18 |
Correct |
3 ms |
67624 KB |
Output is correct |
19 |
Correct |
3 ms |
67624 KB |
Output is correct |
20 |
Correct |
953 ms |
67624 KB |
Output is correct |
21 |
Correct |
3 ms |
67624 KB |
Output is correct |
22 |
Correct |
3 ms |
67624 KB |
Output is correct |
23 |
Correct |
5 ms |
67624 KB |
Output is correct |
24 |
Correct |
6 ms |
67624 KB |
Output is correct |
25 |
Correct |
5 ms |
67624 KB |
Output is correct |
26 |
Execution timed out |
1078 ms |
67768 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |