# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1010731 |
2024-06-29T10:05:41 Z |
gmroh06 |
버스 (JOI14_bus) |
C++17 |
|
178 ms |
27532 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> dp(n + 1, -1), idx(n + 1);
priority_queue<pair<ll, ll>> pq;
pq.emplace(dp[n] = s, n);
while (!pq.empty()) {
auto [cur, loc] = pq.top();
pq.pop();
if (cur != dp[loc]) {
continue;
}
for (ll& i = idx[loc]; i < gr[loc].size(); idx[loc]++) {
auto [nxt, x, y] = gr[loc][i];
if (x > dp[loc]) {
break;
}
if (dp[nxt] < y) {
pq.emplace(dp[nxt] = y, nxt);
}
}
}
return dp[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 |
344 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 |
0 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
604 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 |
21 ms |
4364 KB |
Output is correct |
3 |
Correct |
21 ms |
4440 KB |
Output is correct |
4 |
Correct |
3 ms |
856 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
22 ms |
3380 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
25 ms |
3284 KB |
Output is correct |
10 |
Correct |
22 ms |
4380 KB |
Output is correct |
11 |
Correct |
21 ms |
3676 KB |
Output is correct |
12 |
Correct |
22 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
23732 KB |
Output is correct |
2 |
Correct |
115 ms |
23632 KB |
Output is correct |
3 |
Correct |
95 ms |
23580 KB |
Output is correct |
4 |
Correct |
98 ms |
23632 KB |
Output is correct |
5 |
Correct |
116 ms |
23668 KB |
Output is correct |
6 |
Correct |
107 ms |
23696 KB |
Output is correct |
7 |
Correct |
80 ms |
20312 KB |
Output is correct |
8 |
Correct |
94 ms |
23304 KB |
Output is correct |
9 |
Correct |
98 ms |
23608 KB |
Output is correct |
10 |
Correct |
79 ms |
19536 KB |
Output is correct |
11 |
Correct |
77 ms |
19484 KB |
Output is correct |
12 |
Correct |
99 ms |
19568 KB |
Output is correct |
13 |
Correct |
79 ms |
19444 KB |
Output is correct |
14 |
Correct |
80 ms |
19536 KB |
Output is correct |
15 |
Correct |
92 ms |
19356 KB |
Output is correct |
16 |
Correct |
32 ms |
9852 KB |
Output is correct |
17 |
Correct |
33 ms |
9852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
27476 KB |
Output is correct |
2 |
Correct |
127 ms |
27268 KB |
Output is correct |
3 |
Correct |
112 ms |
27504 KB |
Output is correct |
4 |
Correct |
133 ms |
27532 KB |
Output is correct |
5 |
Correct |
147 ms |
27232 KB |
Output is correct |
6 |
Correct |
178 ms |
27236 KB |
Output is correct |
7 |
Correct |
114 ms |
24456 KB |
Output is correct |
8 |
Correct |
146 ms |
27512 KB |
Output is correct |
9 |
Correct |
121 ms |
27404 KB |
Output is correct |
10 |
Correct |
107 ms |
23540 KB |
Output is correct |
11 |
Correct |
99 ms |
23376 KB |
Output is correct |
12 |
Correct |
137 ms |
23632 KB |
Output is correct |
13 |
Correct |
96 ms |
23388 KB |
Output is correct |
14 |
Correct |
108 ms |
23376 KB |
Output is correct |
15 |
Correct |
99 ms |
23376 KB |
Output is correct |
16 |
Correct |
64 ms |
12976 KB |
Output is correct |