QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#542060 | #437. Fun Tour | makrav | 100 ✓ | 73ms | 19872kb | C++20 | 3.7kb | 2024-08-31 22:25:07 | 2024-08-31 22:25:11 |
Judging History
answer
#include "fun.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
vector<int> createFunTour(int N, int Q) {
if (N == 2) {
return {0, 1};
}
int n = N;
vector<int> path = {0};
for (int v = 1; v < N; v++) {
int x = attractionsBehind(0, v);
if (x >= N / 2 + 1) {
path.push_back(v);
}
}
vector<int> byd(path.size(), 0), D(n), used(n);
used[0] = 1;
for (int i = 1; i < path.size(); i++) {
int d = hoursRequired(0, path[i]);
D[path[i]] = d;
used[path[i]] = 1;
byd[d] = path[i];
}
int centr = byd.back();
vector<int> ds(n);
for (auto &u : path) used[u] = 1;
for (int i = 0; i < n; i++) {
if (!used[i]) ds[i] = hoursRequired(centr, i);
else ds[i] = path.size() - 1 - D[i];
}
vector<int> sons;
for (int i = 0; i < n; i++) {
if (ds[i] == 1) sons.push_back(i);
}
vector<vector<int>> cmp(sons.size());
vector<int> from(n);
for (int i = 0; i < n; i++) {
if (i != centr) {
bool found = false;
for (int j = 0; j < sons.size() - 1; j++) {
if (attractionsBehind(i, sons[j]) > N / 2) {
from[i] = j;
found = true;
cmp[j].push_back(i);
break;
}
}
if (!found) {
from[i] = sons.size() - 1;
cmp.back().push_back(i);
}
}
}
for (int i = 0; i < sons.size(); i++) {
sort(all(cmp[i]), [&](int u, int v){return ds[u] < ds[v];});
}
vector<int> ans = {centr};
int curn = n;
auto solve = [&](auto solve) -> void {
if (cmp.size() == 2) {
if (cmp[0].size() > cmp[1].size()) swap(cmp[0], cmp[1]);
for (int i = 0; i < sz(cmp[1]); i++) {
ans.pb(cmp[1][i]);
if (i < cmp[0].size()) ans.pb(cmp[0][i]);
}
return;
}
for (int i = 0; i < 3; i++) {
if (sz(cmp[i]) == curn / 2) {
for (int j = 0; j < 3; j++) reverse(all(cmp[j]));
for (int j = 1; j < curn; j++) {
if (j & 1) {
ans.pb(cmp[i].back()); cmp[i].pop_back();
} else {
vector<pair<int, int>> cands;
for (int j1 = 0; j1 < 3; j1++) {
if (j1 != i && !cmp[j1].empty()) {
cands.pb({cmp[j1].back(), j1});
}
}
if (cands.size() == 2 && ds[cands[0].first] > ds[cands[1].first]) swap(cands[0], cands[1]);
cmp[cands[0].second].pop_back();
ans.pb(cands[0].first);
}
}
return;
}
}
vector<int> lasts;
for(int i = 0; i < 3; i++) {
assert(!cmp[i].empty());
lasts.pb(cmp[i].back());
}
sort(all(lasts), [&](int i, int j){return ds[i] < ds[j];});
int v1 = lasts[1], v2 = lasts[2];
cmp[from[v1]].pop_back();
cmp[from[v2]].pop_back();
curn -= 2;
solve(solve);
if (from[ans.back()] != from[v1] && ds[v1] >= ds[ans[sz(ans) - 2]] && ds[v2] >= ds[ans.back()]) {
ans.pb(v1); ans.pb(v2);
} else {
ans.pb(v2); ans.pb(v1);
}
};
solve(solve);
reverse(all(ans));
return ans;
}
詳細信息
Subtask #1:
score: 0
Accepted
Test #1:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
2 400000 1 0
output:
0 1
result:
ok correct
Subtask #2:
score: 0
Accepted
Test #3:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
4 400000 1 0 2 0 3 1
output:
3 2 1 0
result:
ok correct
Subtask #3:
score: 0
Accepted
Test #9:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
4 400000 1 0 2 1 3 2
output:
3 0 2 1
result:
ok correct
Subtask #4:
score: 0
Accepted
Test #13:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
4 400000 0 1 0 2 0 3
output:
3 2 1 0
result:
ok correct
Subtask #5:
score: 0
Accepted
Test #20:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
18 400000 1 0 2 0 3 1 4 1 5 2 6 2 7 3 8 3 9 4 10 4 11 5 12 5 13 6 14 6 15 7 16 7 17 8
output:
17 14 16 13 15 12 10 11 9 6 8 5 7 2 4 3 0 1
result:
ok correct
Subtask #6:
score: 0
Accepted
Test #27:
score: 0
Accepted
time: 0ms
memory: 4092kb
input:
18 400000 7 6 8 7 5 8 4 5 3 4 9 3 10 11 12 10 13 12 14 13 9 14 2 9 15 2 16 15 17 16 1 17 0 1
output:
6 0 11 7 1 10 8 17 12 5 16 13 4 15 14 3 2 9
result:
ok correct
Subtask #7:
score: 0
Accepted
Test #33:
score: 0
Accepted
time: 1ms
memory: 3876kb
input:
500 400000 33 414 398 33 254 398 400 254 376 400 302 376 466 302 362 466 301 362 267 301 417 267 413 417 14 413 305 14 353 305 83 353 227 83 57 227 446 57 406 446 154 406 336 154 195 336 405 195 264 405 76 264 203 76 459 203 178 459 72 178 296 72 488 296 404 488 60 404 156 60 393 156 108 393 216 108...
output:
414 212 33 88 398 124 254 399 400 190 376 10 302 366 466 234 362 432 301 28 267 188 417 237 413 64 14 268 305 39 353 349 83 345 227 125 57 70 446 276 406 420 154 369 336 48 195 211 405 482 264 8 76 22 203 487 459 9 178 230 72 339 296 95 488 340 404 50 60 102 156 174 393 47 108 461 216 424 106 181 31...
result:
ok correct
Subtask #8:
score: 0
Accepted
Test #41:
score: 0
Accepted
time: 0ms
memory: 3900kb
input:
501 400000 1 0 2 0 3 1 4 1 5 2 6 2 7 3 8 3 9 4 10 4 11 5 12 5 13 6 14 6 15 7 16 7 17 8 18 8 19 9 20 9 21 10 22 10 23 11 24 11 25 12 26 12 27 13 28 13 29 14 30 14 31 15 32 15 33 16 34 16 35 17 36 17 37 18 38 18 39 19 40 19 41 20 42 20 43 21 44 21 45 22 46 22 47 23 48 23 49 24 50 24 51 25 52 25 53 26 ...
output:
413 349 414 348 415 347 416 346 417 345 418 344 419 343 420 342 421 341 422 340 423 339 424 338 425 337 441 336 427 335 428 350 429 333 430 332 431 331 432 330 433 329 434 328 435 327 436 326 437 325 438 324 439 323 440 322 426 321 383 320 384 319 385 334 386 381 387 380 388 379 389 378 390 377 391 ...
result:
ok correct
Subtask #9:
score: 0
Accepted
Test #51:
score: 0
Accepted
time: 1ms
memory: 4096kb
input:
1000 400000 6 5 7 8 6 7 9 6 11 10 11 12 13 11 14 15 13 14 9 13 16 9 18 17 18 19 20 18 22 21 22 23 20 22 24 20 26 25 26 27 28 26 30 29 30 31 28 30 24 28 16 24 32 16 33 32 35 34 35 36 37 35 39 38 39 40 37 39 41 37 43 42 43 44 45 43 47 46 47 48 45 47 41 45 49 41 50 51 52 50 54 53 54 55 52 54 56 52 58 5...
output:
919 139 921 141 923 323 925 321 867 143 928 319 930 145 932 147 865 149 859 151 936 312 863 153 938 114 940 155 942 307 944 305 861 158 946 303 949 160 951 301 934 299 836 162 885 297 887 164 877 166 889 310 891 116 893 357 895 118 875 355 897 353 917 121 901 351 903 349 873 123 905 347 907 125 871 ...
result:
ok correct
Subtask #10:
score: 0
Accepted
Test #59:
score: 0
Accepted
time: 73ms
memory: 19872kb
input:
99999 400000 11681 58292 11681 63929 49752 11681 30596 74400 30596 39261 49752 30596 19390 49752 89694 31923 19390 89694 54297 19390 42389 12902 42389 60328 72803 42389 69881 43761 69881 95741 72803 69881 96271 72803 63872 20658 63872 93588 35833 63872 48418 44153 35833 48418 96271 35833 54297 96271...
output:
62996 54185 26009 13388 62998 54193 26002 54198 26001 54199 63008 54200 25999 54204 63016 54210 63017 54212 25997 13385 25996 54217 73666 54218 63031 54226 63033 69843 63036 54232 25989 54238 63040 54243 25986 54244 25985 54247 63062 54250 63064 54252 63065 54253 63066 54255 25968 54258 63030 13383 ...
result:
ok correct
Subtask #11:
score: 10
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Subtask #12:
score: 16
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Dependency #6:
100%
Accepted
Dependency #7:
100%
Accepted
Subtask #13:
score: 21
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #5:
100%
Accepted
Dependency #8:
100%
Accepted
Subtask #14:
score: 19
Accepted
Dependency #1:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #6:
100%
Accepted
Dependency #9:
100%
Accepted
Subtask #15:
score: 34
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Dependency #6:
100%
Accepted
Dependency #7:
100%
Accepted
Dependency #8:
100%
Accepted
Dependency #9:
100%
Accepted
Dependency #10:
100%
Accepted
Dependency #11:
100%
Accepted
Dependency #12:
100%
Accepted
Dependency #13:
100%
Accepted
Dependency #14:
100%
Accepted
Extra Test:
score: 0
Extra Test Passed