QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#403969#437. Fun Tourbachbeo2007100 ✓92ms18396kbC++202.2kb2024-05-03 00:27:292024-05-03 00:27:30

Judging History

你现在查看的是最新测评结果

  • [2024-05-03 00:27:30]
  • 评测
  • 测评结果:100
  • 用时:92ms
  • 内存:18396kb
  • [2024-05-03 00:27:29]
  • 提交

answer

#include "fun.h"
#include <bits/stdc++.h>
using namespace std;

std::vector<int> createFunTour(int N, int Q) {
    vector<int> P(N);
    int X=0,Min=N;
    for(int i=0;i<N;i++){
        int sz=attractionsBehind(0,i);
        if(sz>N/2 && sz<Min) X=i,Min=sz;
    }
    vector<int> D(N),cc;
    for(int i=0;i<N;i++){
        D[i]=hoursRequired(X,i);
        if(D[i]==1) cc.push_back(i);
    }
    int S=(int)cc.size();
    vector<vector<int>> G(S);
    for(int i=0;i<N;i++){
        if(i==X) continue;
        int j=0;
        while(j+1<S && hoursRequired(cc[j],i)+D[cc[j]]!=D[i]) j++;
        G[j].push_back(i);
        //cout << j << ' ' << i << '\n';
    }
    for(int i=0;i<S;i++){
        sort(G[i].begin(),G[i].end(),[&](int x,int y){
            return D[x]<D[y];
        });
    }
    //cout << X << '\n';
    int T=0;
    vector<int> A,B;
    if(S==2){
        A=G[0];B=G[1];
        if((int)A.size()>(int)B.size()) swap(A,B);
    }
    else{
        int c=-1;
        while(T<N-1){
            int Max=0;
            for(int i=0;i<S;i++) Max=max(Max,(int)G[i].size());
            if(2*Max==N-T-1) break;
            int u=-1;Max=0;
            for(int i=0;i<S;i++){
                if(c==i) continue;
                if(D[G[i].back()]>Max) Max=D[G[i].back()],u=i;
            }
            assert(u!=-1);
            P[T++]=G[u].back();
            G[u].pop_back();c=u;
        }
        int u=-1;
        for(int i=0;i<S;i++) if(2*(int)G[i].size()==N-T-1) u=i;
        assert(u!=-1);

        for(int i=0;i<S;i++){
            if(u==i) A=G[i];
            else B.insert(B.end(),G[i].begin(),G[i].end());
        }
        if(c!=u) swap(A,B);
        sort(A.begin(),A.end(),[&](int x,int y){
            return D[x]<D[y];
        });
        sort(B.begin(),B.end(),[&](int x,int y){
            return D[x]<D[y];
        });
        assert((int)A.size()==(int)B.size());
    }
    while(!A.empty() || !B.empty()){
        if(!B.empty()) P[T++]=B.back(),B.pop_back();
        if(!A.empty()) P[T++]=A.back(),A.pop_back();
    }
    P[T++]=X;
    //for(int i=0;i<N;i++) cout << P[i] << ' ';
    //cout << '\n';
    return P;
}

詳細信息

Subtask #1:

score: 0
Accepted

Test #1:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

2 400000
1 0

output:

1 0

result:

ok correct

Subtask #2:

score: 0
Accepted

Test #3:

score: 0
Accepted
time: 1ms
memory: 3828kb

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: 4012kb

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: 3716kb

input:

4 400000
0 1
0 2
0 3

output:

1 3 2 0

result:

ok correct

Subtask #5:

score: 0
Accepted

Test #20:

score: 0
Accepted
time: 1ms
memory: 3724kb

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 8 6 7 5 10 2 9 3 4 0 1

result:

ok correct

Subtask #6:

score: 0
Accepted

Test #27:

score: 0
Accepted
time: 1ms
memory: 3716kb

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 1 7 11 17 8 10 16 5 12 15 4 13 3 14 2 9

result:

ok correct

Subtask #7:

score: 0
Accepted

Test #33:

score: 0
Accepted
time: 1ms
memory: 3792kb

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: 1ms
memory: 3876kb

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 285 414 284 415 283 416 282 417 281 418 280 419 279 420 278 421 277 422 276 423 275 424 274 425 273 441 272 427 271 428 286 429 269 430 268 431 267 432 266 433 265 434 264 435 263 436 262 437 261 438 260 439 259 440 258 426 257 383 256 384 255 385 270 386 317 387 316 388 315 389 314 390 313 391 ...

result:

ok correct

Subtask #9:

score: 0
Accepted

Test #51:

score: 0
Accepted
time: 1ms
memory: 3868kb

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:

139 684 141 682 323 680 321 510 143 678 319 676 145 526 147 674 149 672 151 559 312 502 153 668 114 666 155 664 307 512 305 662 158 660 303 561 160 658 301 656 299 654 162 652 297 670 164 722 166 550 310 504 116 717 357 715 118 552 355 713 353 711 121 506 351 709 349 707 123 686 347 703 125 554 345 ...

result:

ok correct

Subtask #10:

score: 0
Accepted

Test #59:

score: 0
Accepted
time: 92ms
memory: 18396kb

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:

54185 62996 13388 26009 54193 62998 54198 26002 54199 26001 54200 63008 54204 25999 54210 63016 54212 63017 13385 25997 54217 25996 54218 73666 54226 63031 69843 63033 54232 63036 54238 25989 54243 63040 54244 25986 54247 25985 54250 63062 54252 63064 54253 63065 54255 63066 54258 25968 13383 63030 ...

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