QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#91258 | #5506. Hyperloop | Denisov | ML | 460ms | 18864kb | C++20 | 4.6kb | 2023-03-28 04:03:16 | 2023-03-28 04:03:18 |
Judging History
answer
//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")
#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
template<typename T>
inline bool umin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
inline bool umax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#ifdef LOCAL
#define D for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define D while (false)
#define LOG(...)
#endif // LOCAL
const int max_n = -1, inf = 1000111222;
inline vector <pii> add(vector <pii> &a, int x) {
for (int i = 0; i < len(a); i++) {
if (a[i].first == x) {
auto b = a;
++b[i].second;
return b;
}
}
vector <pii> new_a(len(a) + 1);
int cnt = 0;
for (int i = 0; i < len(a); ) {
if (a[i].first < x) {
new_a[cnt++] = {x, 1};
x = -inf;
}
else {
new_a[cnt++] = a[i];
++i;
}
}
if (cnt < len(a) + 1) {
new_a[cnt] = {x, 1};
}
return new_a;
}
inline bool check (vector <pii> &a, vector <pii> &b) { /// b > a
for (int i = 0; i < min(len(a), len(b)); i++) {
if (a[i].first < b[i].first) {
return true;
}
if (a[i].first > b[i].first) {
return false;
}
if (a[i].second < b[i].second) {
return true;
}
if (a[i].second > b[i].second) {
return false;
}
}
return len(a) < len(b);
}
inline void test_case () {
int n, m;
cin >> n >> m;
vector <pair<pii, int> > e(m + m);
for (int i = 0; i < m; i++) {
cin >> e[i].first.first >> e[i].first.second >> e[i].second;
--e[i].first.first;
--e[i].first.second;
e[m + i] = {{e[i].first.second, e[i].first.first}, e[i].second};
}
m += m;
sort(all(e));
vector <int> p(n);
for (int i = 0, j = 0; i < n; i++) {
while (j < m && e[j].first.first < i) {
++j;
}
p[i] = j;
}
priority_queue <pii> q;
vector <int> d(n, inf);
d[0] = 0;
q.push({0, 0});
while (!q.empty()) {
int v, dist;
tie(dist, v) = q.top();
q.pop();
if (-dist > d[v]) {
continue;
}
for (int i = p[v]; i < m; i++) {
if (e[i].first.first != v) break;
int to = e[i].first.second;
int len = e[i].second;
if (umin(d[to], d[v] + len)) {
q.push({-d[to], to});
}
}
}
vector <int> order(n);
iota(all(order), 0);
sort(all(order), [&] (int a, int b) {
return d[a] > d[b];
});
vector <vector <pii> > nice(n);
vector <bool> good(n);
vector <int> go(n);
good[n - 1] = true;
for (int v : order) {
if (d[v] > d[n - 1]) {
continue;
}
for (int i = p[v]; i < m; i++) {
if (e[i].first.first != v) {
break;
}
int to = e[i].first.second;
int len = e[i].second;
if (d[to] == d[v] + len && good[to]) {
auto gg = add(nice[to], len);
if (!good[v]) {
good[v] = true;
nice[v] = gg;
go[v] = to;
}
else if (check(nice[v], gg)){
nice[v] = gg;
go[v] = to;
}
}
}
}
vector <int> ans;
int v = 0;
while (v != n - 1) {
ans.pb(v);
v = go[v];
}
ans.pb(n - 1);
cout << len(ans) << '\n';
for (auto &i : ans) {
cout << i + 1 << ' ';
}
cout << '\n';
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
for (int test = 1; test <= t; test++) {
test_case();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3520kb
input:
2 4 6 1 2 1 1 3 2 2 3 1 2 4 2 3 4 1 1 4 4 6 11 1 2 9 2 3 12 3 4 3 4 5 5 5 6 10 6 1 22 2 4 9 3 6 1 4 6 5 2 5 2 3 5 8
output:
3 1 2 4 5 1 2 5 3 6
result:
ok correct (2 test cases)
Test #2:
score: 0
Accepted
time: 321ms
memory: 4176kb
input:
600 320 1547 204 81 13768 232 97 9939 97 249 3719 201 109 14322 183 132 40881 142 143 1 275 186 24548 18 236 7907 30 317 11845 131 130 1 311 300 11704 141 92 41925 174 191 32128 119 120 1 184 183 1 310 309 1 283 270 25477 233 141 36076 212 92 13770 307 110 40656 218 137 14033 180 85 41892 200 199 44...
output:
184 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 89 90 91 92 93 94 95 96 97 98 99 100 101 102 10...
result:
ok correct (600 test cases)
Test #3:
score: 0
Accepted
time: 460ms
memory: 18864kb
input:
4 100000 220000 48940 43355 42347 77914 77913 1 45236 82683 42904 22563 16038 34866 81537 81538 43088 49803 51485 25497 63071 25523 14336 44102 39850 43782 13607 92386 16724 98711 73651 46840 17775 16801 28765 5757 98829 13508 85095 48444 1 9198 43003 32678 14461 14462 1 20245 48742 18138 89120 8911...
output:
35000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
result:
ok correct (4 test cases)
Test #4:
score: -100
Memory Limit Exceeded
input:
4 100000 160000 5533 94547 28459 14992 20984 20548 70133 92512 27510 9013 9012 304 13621 40571 47787 305 306 262 6987 6988 135 16234 16992 40656 26246 49196 27701 19103 60272 44055 91532 91531 38290 70778 68341 35147 32524 32523 13 85786 50300 40970 49277 29735 13942 43446 34519 42455 77623 17031 34...