QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#91257 | #5506. Hyperloop | Denisov | WA | 363ms | 4200kb | C++20 | 4.6kb | 2023-03-28 03:57:50 | 2023-03-28 03:57:54 |
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)) {
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();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3416kb
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 3 4 5 1 2 5 3 6
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 363ms
memory: 4200kb
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:
wrong answer Contestant's path is not optimal lexicographically (test case 29)