# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
995622 |
2024-06-09T13:28:56 Z |
gmroh06 |
버스 (JOI14_bus) |
C++17 |
|
134 ms |
27732 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline void fastio() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
}
int main() {
fastio();
ll n, m, q;
cin >> n >> m;
vector<vector<tuple<ll, ll, ll>>> gr(n + 1);
for (ll i = 0, u, v, x, y; i < m; i++) {
cin >> u >> v >> x >> y;
gr[v].emplace_back(u, y, x);
}
for (ll i = 1; i <= n; i++) {
sort(gr[i].begin(), gr[i].end(), [&](const auto& x, const auto& y) -> bool {
return get<1>(x) < get<1>(y);
});
}
auto cal = [&](ll s) -> ll {
static vector<ll> mem(n + 1, -1), idx(n + 1);
priority_queue<pair<ll, ll>> pq;
pq.emplace(mem[n] = s, n);
while (!pq.empty()) {
auto [cur, loc] = pq.top();
pq.pop();
if (cur != mem[loc]) {
continue;
}
for (ll& i = idx[loc]; i < gr[loc].size(); idx[loc]++) {
auto [nxt, x, y] = gr[loc][i];
if (x > mem[loc]) {
break;
}
if (mem[nxt] < y) {
pq.emplace(mem[nxt] = y, nxt);
}
}
}
return mem[1];
};
cin >> q;
vector<pair<ll, ll>> query(q);
vector<ll> ans(q);
for (ll i = 0; i < q; i++) {
cin >> query[i].first;
query[i].second = i;
}
sort(query.begin(), query.end());
for (auto& [x, idx] : query) {
ans[idx] = cal(x);
}
for (auto& x : ans) {
cout << x << '\n';
}
return 0;
}
Compilation message
bus.cpp: In lambda function:
bus.cpp:46:38: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (ll& i = idx[loc]; i < gr[loc].size(); idx[loc]++) {
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
22 ms |
4496 KB |
Output is correct |
3 |
Correct |
21 ms |
4436 KB |
Output is correct |
4 |
Correct |
3 ms |
884 KB |
Output is correct |
5 |
Correct |
3 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
20 ms |
3376 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
21 ms |
3420 KB |
Output is correct |
10 |
Correct |
23 ms |
4396 KB |
Output is correct |
11 |
Correct |
21 ms |
3668 KB |
Output is correct |
12 |
Correct |
23 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
23596 KB |
Output is correct |
2 |
Correct |
103 ms |
23636 KB |
Output is correct |
3 |
Correct |
111 ms |
23576 KB |
Output is correct |
4 |
Correct |
96 ms |
23636 KB |
Output is correct |
5 |
Correct |
130 ms |
23636 KB |
Output is correct |
6 |
Correct |
99 ms |
23636 KB |
Output is correct |
7 |
Correct |
87 ms |
20308 KB |
Output is correct |
8 |
Correct |
100 ms |
23308 KB |
Output is correct |
9 |
Correct |
107 ms |
23740 KB |
Output is correct |
10 |
Correct |
78 ms |
19540 KB |
Output is correct |
11 |
Correct |
78 ms |
19284 KB |
Output is correct |
12 |
Correct |
84 ms |
19444 KB |
Output is correct |
13 |
Correct |
80 ms |
19520 KB |
Output is correct |
14 |
Correct |
86 ms |
19284 KB |
Output is correct |
15 |
Correct |
80 ms |
19384 KB |
Output is correct |
16 |
Correct |
33 ms |
9812 KB |
Output is correct |
17 |
Correct |
31 ms |
9808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
27492 KB |
Output is correct |
2 |
Correct |
119 ms |
27224 KB |
Output is correct |
3 |
Correct |
125 ms |
27732 KB |
Output is correct |
4 |
Correct |
123 ms |
27552 KB |
Output is correct |
5 |
Correct |
122 ms |
27216 KB |
Output is correct |
6 |
Correct |
117 ms |
27220 KB |
Output is correct |
7 |
Correct |
114 ms |
24404 KB |
Output is correct |
8 |
Correct |
118 ms |
27476 KB |
Output is correct |
9 |
Correct |
126 ms |
27412 KB |
Output is correct |
10 |
Correct |
102 ms |
23380 KB |
Output is correct |
11 |
Correct |
107 ms |
23280 KB |
Output is correct |
12 |
Correct |
100 ms |
23636 KB |
Output is correct |
13 |
Correct |
106 ms |
23380 KB |
Output is correct |
14 |
Correct |
103 ms |
23380 KB |
Output is correct |
15 |
Correct |
104 ms |
23380 KB |
Output is correct |
16 |
Correct |
73 ms |
13032 KB |
Output is correct |