QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#106115#4744. CheerleaderKostlin100 ✓141ms5820kbC++142.2kb2023-05-16 17:22:022023-05-16 17:22:04

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-16 17:22:04]
  • 评测
  • 测评结果:100
  • 用时:141ms
  • 内存:5820kb
  • [2023-05-16 17:22:02]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
#define fi first
#define sc second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int N=(1<<17)+5,oo=1e9,mod=998244353;
inline int read() {
    int x=0,flag=0;char ch=getchar();
    while(ch<'0'||ch>'9') {flag|=(ch=='-');ch=getchar();}
    while('0'<=ch&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return flag?-x:x;
}
inline int mx(int x,int y) {return x>y?x:y;}
inline int mn(int x,int y) {return x<y?x:y;}
inline void swp(int &x,int &y) {x^=y^=x^=y;}
inline int as(int x) {return x>0?x:-x;}
inline void add(int&x,int y) {x=(x+y>=mod?x+y-mod:x+y);}

int n,a[N],b[N],t[N][2],ID,Pos;ll T[2],ans=1ll<<60;
inline void solve(int O) {
    ll sum=0; int id=0;
    for(int o=n;o>=1;--o) {
        for(int i=0;i<(1<<n);++i)
            if((b[i]>>(o-1))&1) {
                T[0]+=t[b[i]>>o][0];
                ++t[b[i]>>o][1];
            } else {
                T[1]+=t[b[i]>>o][1];
                ++t[b[i]>>o][0];
            }
        if(T[0]<T[1]) {
            sum+=T[0];
            id|=(1<<(o-1));
        } else {
            sum+=T[1];
        }
        for(int i=0;i<(1<<(n-o));++i) t[i][0]=t[i][1]=0;
        T[0]=T[1]=0;
    }
    if(ans>sum) {
        ans=sum;
        Pos=O;
        ID=id;
    }
}
int vc[N];
inline void add(int V) {vc[++vc[0]]=V;}
inline void print() {for(int i=1;i<=vc[0];++i) putchar('0'+vc[i]);}
int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
    freopen("1.out","w",stdout);
#endif
    n=read();
    for(int i=0;i<(1<<n);++i) a[read()]=i;
    if(n==0) {
        printf("0\n");
        return 0;
    }
    for(int o=0;o<n;++o) {
        for(int i=0;i<(1<<n);++i) {
            b[i]=0;
            for(int j=o-1;j>=0;--j) b[i]=2*b[i]+((a[i]>>j)&1);
            for(int j=n-1;j>=o;--j) b[i]=2*b[i]+((a[i]>>j)&1);
        }
        solve(o);
    }
    for(int i=1;i<=Pos;++i) add(2);
    add(2);
    for(int i=0;i<n;++i) {
        if((ID>>i)&1) add(1);
        if(i!=n-1)add(2);
    }
    printf("%lld\n",ans);
    print();
    return 0;
}

详细

Subtask #1:

score: 16
Accepted

Test #1:

score: 16
Accepted
time: 1ms
memory: 3440kb

input:

0
0

output:

0

result:

ok all correct

Test #2:

score: 16
Accepted
time: 0ms
memory: 5692kb

input:

4
4 2 14 9 3 1 12 8 6 5 13 11 7 0 15 10

output:

7
22212212

result:

ok all correct

Test #3:

score: 16
Accepted
time: 0ms
memory: 3540kb

input:

4
11 12 14 6 2 1 5 4 8 0 15 7 3 10 9 13

output:

36
222221221

result:

ok all correct

Test #4:

score: 16
Accepted
time: 2ms
memory: 3400kb

input:

3
4 3 7 6 1 2 0 5

output:

6
2221

result:

ok all correct

Subtask #2:

score: 10
Accepted

Test #5:

score: 10
Accepted
time: 2ms
memory: 5528kb

input:

6
63 59 62 61 51 50 52 56 39 48 46 41 33 35 36 40 20 24 26 32 19 18 29 22 11 12 9 17 2 3 0 4 55 58 57 60 45 53 49 54 43 42 44 47 31 34 37 38 25 28 30 27 15 21 23 16 6 13 14 10 8 1 5 7

output:

86
222222122212121

result:

ok all correct

Test #6:

score: 10
Accepted
time: 1ms
memory: 5476kb

input:

7
77 65 92 84 109 99 121 115 12 4 28 19 44 37 62 50 79 70 93 86 110 102 126 119 14 5 30 21 45 36 60 53 78 69 95 85 108 100 125 117 13 7 29 22 48 38 66 55 76 73 94 87 112 103 127 118 15 6 31 23 46 39 61 54 72 64 88 81 105 96 120 111 8 0 26 18 40 33 57 49 74 63 90 80 106 101 122 113 9 1 27 17 41 32 56...

output:

65
22222221212221

result:

ok all correct

Test #7:

score: 10
Accepted
time: 3ms
memory: 3692kb

input:

7
20 63 87 73 42 91 83 93 88 117 126 52 123 44 115 110 14 84 76 26 78 64 22 59 122 2 17 5 74 57 98 9 51 102 39 49 70 114 37 121 99 28 100 36 13 46 120 48 58 106 4 75 72 19 54 97 23 25 71 33 24 8 11 29 30 66 67 0 124 38 10 32 77 113 65 27 62 68 43 107 7 55 53 105 108 15 90 3 85 79 69 116 112 50 60 82...

output:

3746
222212121221212

result:

ok all correct

Test #8:

score: 10
Accepted
time: 2ms
memory: 3448kb

input:

7
43 45 104 123 75 116 83 33 77 52 42 54 81 91 79 61 58 87 0 118 26 3 86 29 72 65 32 97 103 12 101 100 98 112 28 80 68 47 41 48 74 30 53 108 27 120 22 119 99 114 9 34 110 38 95 13 31 39 5 35 10 19 71 63 76 62 106 66 36 1 121 56 126 69 124 49 15 23 50 24 84 85 21 55 107 60 89 93 25 73 17 82 94 109 44...

output:

3756
222222122122121

result:

ok all correct

Subtask #3:

score: 25
Accepted

Test #9:

score: 25
Accepted
time: 3ms
memory: 3472kb

input:

11
411 415 409 410 403 405 402 408 395 396 393 397 389 390 384 387 443 447 444 438 441 436 433 439 426 428 425 430 421 424 419 423 475 479 469 476 470 473 465 468 463 462 460 457 450 456 449 452 509 512 505 508 497 504 499 502 498 495 490 488 487 486 483 481 288 284 280 283 279 282 274 267 270 273 2...

output:

2465
222222222221221212122212122

result:

ok all correct

Test #10:

score: 25
Accepted
time: 2ms
memory: 5476kb

input:

11
1437 1331 1823 1838 1256 196 556 1205 419 56 716 1584 1618 1439 1739 240 558 1662 255 1173 1407 250 107 331 371 1143 570 147 91 1902 135 471 1033 512 937 438 1430 1790 1998 545 533 1259 755 102 1248 75 767 562 1178 1853 1476 1354 1058 1239 1026 462 1781 989 118 1659 1308 1993 1623 1478 1631 1371 ...

output:

999799
22222122212221221221

result:

ok all correct

Test #11:

score: 25
Accepted
time: 0ms
memory: 5440kb

input:

11
1603 1143 1086 195 325 1179 669 739 893 874 1624 840 0 1870 1816 653 462 1129 2042 596 574 701 161 85 1760 1554 304 42 937 1410 386 259 607 181 1374 301 838 923 1732 196 1126 117 100 1824 1923 40 1336 682 760 1392 379 25 287 1434 298 1060 1679 1442 1378 1289 1342 1364 402 209 549 1254 833 4 585 1...

output:

1017974
22212222121221212121

result:

ok all correct

Test #12:

score: 25
Accepted
time: 2ms
memory: 3604kb

input:

11
1248 1534 634 712 429 1184 249 629 1752 1017 140 172 326 873 1516 673 698 593 1252 177 291 739 1322 1051 146 1021 175 1892 543 325 1301 39 1466 762 583 1350 48 65 1599 1948 237 1988 1928 504 933 898 384 1609 1996 1114 54 1038 689 1053 1811 1470 1639 1143 1986 367 1935 368 486 1476 1734 1009 1343 ...

output:

1014489
22212121222122222

result:

ok all correct

Subtask #4:

score: 21
Accepted

Test #13:

score: 21
Accepted
time: 29ms
memory: 3876kb

input:

15
21604 21600 21612 21608 21620 21616 21628 21624 21572 21568 21580 21576 21588 21584 21596 21592 21540 21536 21548 21544 21556 21552 21564 21560 21508 21504 21516 21512 21524 21520 21532 21528 21732 21728 21740 21736 21748 21744 21756 21752 21700 21696 21708 21704 21716 21712 21724 21720 21668 216...

output:

0
2222222222222222122212122221221221

result:

ok all correct

Test #14:

score: 21
Accepted
time: 29ms
memory: 3972kb

input:

15
20226 20234 20242 20250 20258 20266 20274 20282 20290 20298 20306 20314 20322 20330 20338 20346 20354 20362 20370 20378 20386 20394 20402 20410 20418 20426 20434 20442 20450 20458 20466 20474 19970 19978 19986 19994 20002 20010 20018 20026 20034 20042 20050 20058 20066 20074 20082 20090 20098 201...

output:

0
222222222222221222222212121212221

result:

ok all correct

Test #15:

score: 21
Accepted
time: 59ms
memory: 5772kb

input:

16
10240 10368 10496 10624 10752 10880 11008 11136 11264 11392 11520 11648 11776 11904 12032 12160 8192 8320 8448 8576 8704 8832 8960 9088 9216 9344 9472 9600 9728 9856 9984 10112 14336 14464 14592 14720 14848 14976 15104 15232 15360 15488 15616 15744 15872 16000 16128 16256 12288 12416 12544 12672 ...

output:

0
222222222222222222222122122

result:

ok all correct

Subtask #5:

score: 28
Accepted

Test #16:

score: 28
Accepted
time: 141ms
memory: 5820kb

input:

17
108070 110117 112165 114211 99876 101925 103973 106020 124454 126501 128549 130597 116259 118308 120353 122403 75302 77348 79396 81446 67108 69157 71201 73253 91684 93734 95780 97829 83493 85541 87587 89637 42532 44581 46628 48678 34341 36390 38438 40484 58917 60966 63011 65061 50726 52773 54821 ...

output:

53311
2222222122122212222121222122121

result:

ok all correct

Test #17:

score: 28
Accepted
time: 133ms
memory: 5188kb

input:

17
75837 76857 73791 74814 79935 80959 77884 78908 67648 68666 65602 66619 71744 72765 69690 70716 92220 93245 90176 91200 96318 97342 94272 95293 84030 85056 81987 83008 88129 89153 86072 87100 108604 109629 106561 107579 112703 113730 110658 111680 100411 101436 98367 99395 104515 105534 102460 10...

output:

163471
22222222212121212122222212212221

result:

ok all correct

Test #18:

score: 28
Accepted
time: 125ms
memory: 5048kb

input:

17
92113 129195 47835 66048 129446 34346 126005 42566 129210 111676 2682 89233 15399 81683 15098 55066 53079 75845 66395 32917 71194 3609 120049 117983 56986 42518 44280 95544 5981 21757 54754 64586 122559 121796 17196 119125 205 30901 11235 118420 126233 14846 73794 113383 108584 114768 36500 11785...

output:

4275522633
221212212222121222222221

result:

ok all correct

Test #19:

score: 28
Accepted
time: 126ms
memory: 5596kb

input:

17
92322 51767 111226 64460 6196 13421 125253 51750 15230 97275 41989 117886 20194 75184 95152 88933 8036 58671 130013 21916 45334 123047 84123 73264 38130 128660 32889 57999 102130 96989 29361 97688 97838 85525 49090 117404 47054 99851 14578 100309 16439 75149 119200 103093 127390 109353 85079 1209...

output:

4279272725
222222222221212121222122122121212121

result:

ok all correct

Test #20:

score: 28
Accepted
time: 124ms
memory: 5104kb

input:

17
1674 70370 46159 24461 83033 42214 130759 91255 101358 43278 107651 43774 106705 29276 53014 88456 117145 940 54116 47646 5995 21249 113861 62083 27562 118926 85344 102863 126417 109762 93838 31368 32134 43627 99280 27738 98923 32997 129287 118749 128460 65120 117118 26545 75041 33664 33599 10162...

output:

4278896387
222222222222222212212212222122222

result:

ok all correct