QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#182840 | #4744. Cheerleader | yllcm | 84 | 150ms | 6868kb | C++14 | 1.8kb | 2023-09-18 16:50:01 | 2023-09-18 16:50:02 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define FR first
#define SE second
#define int long long
using namespace std;
inline int read() {
int x = 0; bool op = false;
char c = getchar();
while(!isdigit(c))op |= (x == '-'), c = getchar();
while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return op ? -x : x;
}
const int N = (1 << 17) + 10;
const int INF = 1e16;
int n;
int p[N], cnt[N][2];
signed main() {
n = read();
for(int i = 0; i < (1 << n); i++)p[read()] = i;
int ans = INF, pos = 0, S = 0;
for(int i = 0; i <= n; i++) {
int val = 0, res = 0;
// for(int k = 0; k < (1 << n); k++)printf("%d ", p[k]); putchar('\n');
for(int j = n - 1; ~j; j--) {
int sum[2] = {0};
for(int k = 0; k < (1 << n); k++) {
int c = p[k] >> j & 1;
sum[c] += cnt[p[k] >> (j + 1)][c ^ 1];
cnt[p[k] >> (j + 1)][c]++;
// printf("sum:%d %d\n", sum[0], sum[1]);
}
// printf("qwq:%d %d %d\n", j, sum[0], sum[1]);
for(int k = 0; k < (1 << n); k++) {
int c = p[k] >> j & 1;
cnt[p[k] >> (j + 1)][c]--;
}
int now = sum[1] < sum[0];
if(now)val |= (1 << j);
res += min(sum[0], sum[1]);
}
// printf("stra:%d\n", val);
if(res < ans)ans = res, pos = i, S = val;
for(int j = 0; j < (1 << n); j++) {
p[j] = (p[j] >> 1) | ((p[j] & 1) * (1 << (n - 1)));
}
}
printf("%lld\n", ans);
// printf("S:%d %d\n", pos, S);
string opt = "";
for(int i = 0; i <= pos; i++)opt += "2";
for(int i = 0; i < n; i++) {
if(S >> i & 1)opt += "1";
if(i + 1 < n)opt += "2";
}
cout << opt << '\n';
return 0;
}
詳細信息
Subtask #1:
score: 0
Checker Runtime Error
Test #1:
score: 0
Checker Runtime Error
input:
0 0
output:
0 2
result:
Subtask #2:
score: 10
Accepted
Test #5:
score: 10
Accepted
time: 0ms
memory: 5840kb
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: 0ms
memory: 3960kb
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: 1ms
memory: 6112kb
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: 0ms
memory: 3736kb
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: 1ms
memory: 3740kb
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: 1ms
memory: 3696kb
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: 1ms
memory: 3996kb
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: 0ms
memory: 6056kb
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: 23ms
memory: 4316kb
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: 27ms
memory: 4220kb
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: 65ms
memory: 6260kb
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: 150ms
memory: 6004kb
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: 143ms
memory: 5708kb
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: 126ms
memory: 6856kb
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: 124ms
memory: 6008kb
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: 126ms
memory: 6868kb
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