QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#486974 | #437. Fun Tour | Dimash | 100 ✓ | 87ms | 19600kb | C++23 | 4.0kb | 2024-07-22 14:28:56 | 2024-07-22 14:28:56 |
Judging History
answer
#include "fun.h"
#include <bits/stdc++.h>
using namespace std;
int n,q;
int find_cen(){
vector<pair<int,int>> a;
for(int i = 1;i < n;i++){
int s = attractionsBehind(0,i);
if(s*2 > n){
a.emplace_back(s,i);
}
}
if(a.empty()) return 0;
sort(a.begin(),a.end());
return a[0].second;
}
const int N = 1e5 + 12;
int val[N];
vector<int> createFunTour(int nn, int qq) {
if(nn == 2){
return {0,1};
}
n = nn;q = qq;
int c = find_cen();
array<int,3> ver = {-1,-1,-1};
array<vector<pair<int,int>>,3> vec;
for(int i = 0;i < n;i++){
if(i == c) continue;
val[i] = hoursRequired(c,i);
if(val[i] == 1){
for(int j = 0;j < 3;j++){
if(ver[j] == -1){
ver[j] = i;
break;
}
}
}
}
vector<int> res;
for(int i = 0;i < n;i++){
if(i == c) continue;
if(val[i] == 1){
if(i == ver[0]){
vec[0].push_back({1,i});
}else if(i == ver[1]){
vec[1].push_back({1,i});
}else{
vec[2].push_back({1,i});
}
continue;
}
int _ = -1;
for(int k = 0;k < 2;k++){
if(val[i] - 1 == hoursRequired(i,ver[k])){
_=k;
break;
}
}
if(_ == -1) _ = 2;
vec[_].push_back({val[i],i});
}
int lst = -1;
int l = 0;
bool OK = true;
int _x = (int)vec[0].size(),_y = (int)vec[1].size(),_z = (int)vec[2].size();
if(true){
vector<pair<int,int>> cc;
for(int i = 0;i < 3;i++){
cc.push_back({(int)vec[i].size(),i});
}
sort(cc.begin(),cc.end());
vec[(int)cc[0].second].push_back({0,c});
}
for(int i = 0;i < 3;i++){
sort(vec[i].begin(),vec[i].end());
}
while(true){
int _x = (int)vec[0].size(),_y = (int)vec[1].size(),_z = (int)vec[2].size();
if(_x == _y + _z || _y == _x + _z || _z == _x + _y){
break;
}
if(!_x || !_y || !_z){
int mx = max({_x,_y,_z});
for(int i = 0;i < 3;i++){
if((int)vec[i].size() == mx){
lst = i;
res.push_back(vec[i].back().second);
vec[i].pop_back();
}
}
break;
}
pair<int,int> mx = {-1,-1};
int id = -1;
auto upd = [&](vector<pair<int,int>> &a,int j){
if(j != lst && (int)a.size()){
pair<int,int> nv = make_pair(a.back().first,(int)a.size());
if(nv > mx){
mx = nv;
id = j;
}
}
};
auto del = [&](vector<pair<int,int>> &x){
res.push_back(x.back().second);
x.pop_back();
};
int cc = 0;
for(int i = 0;i < 3;i++){
if((int)vec[i].empty()) cc++;
upd(vec[i],i);
}
lst = id;
del(vec[id]);
}
vector<int> X,Y;
vector<pair<int,int>> bff;
for(int i = 0;i < 3;i++){
bff.push_back({(int)vec[i].size(),i});
}
sort(bff.begin(),bff.end());
bool ok = false;
for(int i = 0;i < 3;i++){
int j = bff[i].second;
if(i < 2){
if(lst == j) ok = 1;
for(auto f:vec[j]){
X.push_back(f.second);
}
}else{
for(auto f:vec[j]){
Y.push_back(f.second);
}
}
}
if(ok){
X.swap(Y);
}
auto cmp = [&](int x,int y)->bool{
return val[x] > val[y];
};
assert((int)X.size() == (int)Y.size());
sort(X.begin(),X.end(),cmp);
sort(Y.begin(),Y.end(),cmp);
for(int i = 0;i < (int)X.size();i++){
res.push_back(X[i]);
res.push_back(Y[i]);
}
return res;
}
詳細信息
Subtask #1:
score: 0
Accepted
Test #1:
score: 0
Accepted
time: 0ms
memory: 4088kb
input:
2 400000 1 0
output:
0 1
result:
ok correct
Subtask #2:
score: 0
Accepted
Test #3:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
4 400000 1 0 2 0 3 1
output:
2 3 0 1
result:
ok correct
Subtask #3:
score: 0
Accepted
Test #9:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
4 400000 1 0 2 1 3 2
output:
0 3 1 2
result:
ok correct
Subtask #4:
score: 0
Accepted
Test #13:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
4 400000 0 1 0 2 0 3
output:
2 1 3 0
result:
ok correct
Subtask #5:
score: 0
Accepted
Test #20:
score: 0
Accepted
time: 0ms
memory: 4096kb
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:
14 17 13 16 12 15 11 10 6 8 5 9 2 7 4 0 1 3
result:
ok correct
Subtask #6:
score: 0
Accepted
Test #27:
score: 0
Accepted
time: 0ms
memory: 3796kb
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:
0 6 11 1 7 10 17 8 12 16 5 13 15 4 14 2 9 3
result:
ok correct
Subtask #7:
score: 0
Accepted
Test #33:
score: 0
Accepted
time: 0ms
memory: 3904kb
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:
212 414 88 33 124 398 399 254 190 400 10 376 366 302 234 466 432 362 28 301 188 267 237 417 64 413 268 14 39 305 349 353 345 83 125 227 70 57 276 446 420 406 369 154 48 336 211 195 482 405 8 264 22 76 487 203 9 459 230 178 339 72 95 296 340 488 50 404 102 60 174 156 47 393 461 108 424 216 181 106 13...
result:
ok correct
Subtask #8:
score: 0
Accepted
Test #41:
score: 0
Accepted
time: 1ms
memory: 3804kb
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:
500 318 499 317 498 382 497 316 496 381 495 315 494 380 493 314 492 379 491 313 490 378 489 312 488 377 487 311 486 376 485 310 484 375 483 309 482 374 481 308 480 373 479 307 478 372 477 306 476 371 475 305 474 370 473 304 472 369 471 303 470 368 469 302 468 367 467 301 466 366 465 300 464 365 463 ...
result:
ok correct
Subtask #9:
score: 0
Accepted
Test #51:
score: 0
Accepted
time: 1ms
memory: 3928kb
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:
448 811 446 808 444 806 442 804 440 802 438 799 436 796 434 790 432 788 430 786 428 784 426 782 424 780 422 777 420 773 414 771 412 768 410 764 408 761 406 758 404 754 402 752 400 749 398 747 396 745 391 735 389 733 385 731 383 729 381 727 379 725 357 722 355 717 353 715 351 713 349 711 347 709 345 ...
result:
ok correct
Subtask #10:
score: 0
Accepted
Test #59:
score: 0
Accepted
time: 87ms
memory: 19600kb
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:
99998 33779 33669 33736 33633 33745 33635 33747 33636 33753 33639 33754 33648 33758 33651 33761 33652 33765 33655 33770 33659 33772 33661 33774 33662 33734 33628 33785 33674 33786 33675 33792 33676 33796 33679 33798 33685 33799 33686 33800 33692 33801 33694 33805 33697 33806 33701 33814 33703 33665 ...
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