QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#765678 | #8324. 迷宫守卫 | dieselhuang | 100 ✓ | 114ms | 6232kb | C++14 | 1.2kb | 2024-11-20 14:59:07 | 2024-11-20 14:59:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf = 1e12+5;
int n, N, tot, b[65550], c[65550], ans[65550];
ll k, a[65550], f[131090];
ll calc(int u, int x){
if(u >= N) f[u] = (b[u - N] >= x ? 0 : inf);
else f[u] = calc(u << 1, x) + min(a[u], calc(u << 1 | 1, x));
return f[u];
}
ll dfs(int u, ll x, int dep){
if(dep < 0){ ans[++tot] = b[u - N]; return 0; }
int l = 1, r = 1 << n, md;
ll res = 0;
while(l < r){
md = l + r + 1 >> 1;
if(calc(u, md) <= x) l = md;
else r = md - 1;
}
if(c[l] >> dep & 1){
res += dfs(u << 1 | 1, x - f[u << 1], dep - 1);
res += dfs(u << 1, x - res, dep - 1);
}else{
res += dfs(u << 1, x - f[u] + f[u << 1], dep - 1);
if(res + f[u << 1 | 1] > x) res += a[u];
res += dfs(u << 1 | 1, x - res, dep - 1);
}
return res;
}
void solve(){
tot = 0;
int i;
scanf("%d%lld", &n, &k); N = 1 << n;
for(i = 1; i < N; i++) scanf("%lld", &a[i]);
for(i = 0; i < N; i++){
scanf("%d", &b[i]); c[b[i]] = i;
}
dfs(1, k, n - 1);
for(i = 1; i <= tot; i++) printf("%d ", ans[i]);
printf("\n");
}
int main()
{
int t;
scanf("%d", &t);
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 5
Accepted
time: 0ms
memory: 3936kb
input:
5 4 41704513771 63172871346 30595220734 16095671102 3822055819 13738718698 5991071599 14075850903 6874431191 1954448141 4475339255 4509212246 3504301339 4327559573 3485545593 2074035498 7 9 5 16 3 4 1 11 14 12 2 8 15 6 13 10 4 63715445249 61413836337 11125139971 8494516376 13086757419 19161322522 93...
output:
6 15 10 13 12 14 2 8 7 9 5 16 1 11 3 4 3 6 1 15 8 5 12 10 7 4 9 13 11 16 2 14 1 16 7 4 15 9 3 13 2 12 6 14 5 11 8 10 11 16 1 2 5 12 6 9 14 8 10 13 3 7 4 15 2 6 10 5 13 12 7 3 14 8 16 11 15 4 1 9
result:
ok 5 lines
Test #2:
score: 5
Accepted
time: 0ms
memory: 3776kb
input:
5 4 77339380239 81895899866 48344406140 3046718575 7110699715 3972565764 7732374665 6292498163 12486498794 3363604 9980601599 6263469257 3057425890 2429533238 4572510501 2187576167 15 2 5 7 1 13 14 10 3 4 16 8 9 11 6 12 4 37630135888 44732450063 40210162157 6384089682 4618779030 8328589818 147568590...
output:
3 4 16 8 9 11 6 12 15 2 5 7 1 13 10 14 10 8 5 2 14 3 1 4 11 12 13 16 6 15 7 9 1 15 16 2 13 3 4 14 5 11 8 6 7 9 12 10 4 12 11 1 3 10 8 9 5 14 15 2 7 6 13 16 8 10 2 14 11 12 15 3 1 16 4 9 5 7 6 13
result:
ok 5 lines
Test #3:
score: 5
Accepted
time: 0ms
memory: 3936kb
input:
5 4 34893391512 26053943776 45137145772 9525790347 6244540920 15146115409 8558045030 2197707629 2912706108 8598620741 9616527941 5107315902 7164914802 3758081752 1728413392 3704449708 1 5 3 2 16 15 11 9 7 10 12 13 6 14 8 4 4 31567183393 10985614313 25547317620 20499357354 3806371768 864415909 420391...
output:
1 5 3 2 16 15 9 11 4 8 6 14 7 10 12 13 5 3 14 8 15 1 11 7 4 10 6 12 9 13 2 16 8 5 16 14 15 1 2 11 12 4 9 10 3 7 6 13 3 1 4 12 7 15 8 14 6 9 2 5 10 11 13 16 16 7 5 2 8 13 10 15 9 6 3 11 1 12 4 14
result:
ok 5 lines
Test #4:
score: 5
Accepted
time: 0ms
memory: 3860kb
input:
5 4 64526803118 81700304744 29570105266 13540707295 5272323562 7638728067 8087907239 2844705697 12147211174 5137101764 358865602 4913699397 2913573812 3870170710 2834045717 2569759294 3 6 4 13 1 8 11 12 9 16 2 5 7 14 15 10 4 48301519274 22007257328 28325952217 10828692751 6900017612 3320794226 42011...
output:
3 6 4 13 1 8 11 12 9 16 2 5 7 14 15 10 7 9 14 5 2 8 3 1 10 13 12 15 4 11 6 16 6 10 8 9 15 7 4 5 12 2 1 16 14 11 3 13 10 6 15 12 8 1 11 4 14 16 7 9 5 3 13 2 9 8 7 16 12 14 4 10 15 2 11 5 6 3 1 13
result:
ok 5 lines
Test #5:
score: 5
Accepted
time: 0ms
memory: 3980kb
input:
5 4 4863158478 40607600527 2421619125 32450416748 10777143852 5594001099 11510465755 2056752878 7334350461 5373375310 7205056137 494938545 3987861103 3739397274 7072693146 4300805097 8 12 14 9 1 11 7 2 13 5 15 10 6 16 3 4 4 50212387584 1103380725 64230244 17714471343 22345342654 11697933803 95423187...
output:
5 13 10 15 6 16 3 4 8 12 9 14 1 11 2 7 4 15 6 2 9 11 3 14 8 12 1 5 7 10 13 16 7 3 13 9 1 15 2 14 10 16 6 8 11 5 12 4 2 8 12 5 16 7 1 15 10 14 4 6 11 9 3 13 1 16 6 10 7 15 13 14 11 2 12 3 4 8 9 5
result:
ok 5 lines
Test #6:
score: 5
Accepted
time: 0ms
memory: 3984kb
input:
5 6 54745168585 23433156564 23536806253 15372713850 18216219454 8589226497 10865021681 2253546280 907002273 5317503603 475806625 82106518 690500370 6959464451 6238313289 2696179814 2324765017 2290127697 3363593390 342590783 121348581 771888970 4362965169 3207675963 2439991837 587957532 1343945881 18...
output:
53 54 56 55 51 52 49 50 58 57 59 60 61 62 63 64 37 38 39 40 34 33 36 35 41 42 43 44 47 48 45 46 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 17 19 20 21 22 23 24 25 26 27 28 29 30 31 32 12 11 10 9 13 14 15 16 1 2 4 3 5 6 7 8 17 18 19 20 22 21 23 24 25 26 27 28 30 29 31 32 16 15 14 13 12 11 10 9 8 7 6...
result:
ok 5 lines
Test #7:
score: 5
Accepted
time: 0ms
memory: 3980kb
input:
5 6 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 26 38 60 53 48 54 5 32 19 27 20 7 4 61 44 30 62 63 37 43 9 58 33 13 24 18 50 6 34 3 2 57 41 29 28 55 52 17 8 1 22 10 46 40 16 36 15 21 23 45 49 64 42 35 39 11 47 31 12...
output:
26 38 60 53 48 54 5 32 19 27 20 7 4 61 44 30 62 63 37 43 9 58 33 13 6 50 18 24 2 57 3 34 1 8 17 52 28 55 29 41 10 22 40 46 15 21 16 36 11 39 35 42 23 45 49 64 12 14 31 47 25 56 51 59 1 31 7 14 2 3 5 8 6 24 20 23 9 28 13 27 4 25 10 15 12 30 19 29 11 16 18 26 17 32 21 22 2 32 12 17 7 14 11 31 3 19 1...
result:
ok 5 lines
Test #8:
score: 5
Accepted
time: 0ms
memory: 3800kb
input:
5 6 15 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 35 4 24 16 55 20 49 5 17 32 25 14 23 19 57 18 31 1 45 8 3 58 2 59 60 51 40 13 9 21 61 29 46 41 30 44 42 56 48 7 27 28 22 54 52 34 47 26 43 10 33 11 63 62 37 50 38 39 6...
output:
35 4 24 16 55 20 49 5 17 32 25 14 23 19 57 18 9 21 29 61 13 40 51 60 31 1 45 8 2 59 3 58 6 53 38 39 12 64 15 36 10 43 11 33 37 50 62 63 7 48 42 56 30 44 41 46 22 54 27 28 26 47 34 52 5 17 28 31 9 16 13 24 1 18 8 20 11 25 26 32 2 22 3 12 6 23 7 19 4 27 15 30 10 14 21 29 28 18 25 30 26 32 20 17 1 27...
result:
ok 5 lines
Test #9:
score: 5
Accepted
time: 0ms
memory: 3844kb
input:
5 6 41682514268 65512460533 23389539380 17127541806 13879623608 18454598020 11859665553 4427727406 9224733854 10393341296 8919804232 8517294999 7182700425 6740147596 4027193471 2058512521 792633359 4533477482 980684284 2664612081 4521381730 2856886140 1715375705 1335499956 1378534167 1242250449 3240...
output:
15 48 14 26 33 17 37 51 21 38 5 52 34 30 41 18 32 45 2 36 46 57 1 20 40 49 13 54 53 3 7 23 16 29 35 63 19 28 31 59 22 24 27 43 6 9 47 64 39 56 8 50 10 12 44 61 42 11 58 60 4 62 25 55 10 24 30 6 23 4 1 9 13 25 14 27 31 26 8 18 11 12 16 7 5 15 21 29 2 22 17 19 3 20 28 32 2 27 22 24 9 13 31 17 26 19 ...
result:
ok 5 lines
Test #10:
score: 5
Accepted
time: 0ms
memory: 3936kb
input:
5 6 24811678845 59366612184 49154633743 6012028601 18488464455 3698079115 15237755546 9897513757 11297313825 1235390268 9537679832 6527345169 6788541803 6092835632 3757166512 2775821228 5038810767 5132680421 224613865 3922090240 3516928234 4550183827 807384027 3474382046 2163118984 1933277169 237629...
output:
3 22 7 52 9 49 2 57 16 26 29 24 58 6 40 25 5 17 23 56 53 27 50 43 10 45 1 59 34 13 36 54 4 47 46 8 48 14 61 64 18 31 51 55 60 39 44 12 21 62 35 63 28 15 37 33 32 42 41 19 38 30 20 11 1 28 5 7 19 24 18 26 4 17 13 31 12 14 3 2 27 25 11 15 8 30 6 10 29 32 16 21 9 22 20 23 5 12 25 9 24 21 32 31 8 4 30...
result:
ok 5 lines
Test #11:
score: 5
Accepted
time: 2ms
memory: 4048kb
input:
8 11 8529168063 96069180507 14546522039 16201831539 11081688135 14127492888 5483527826 5423117536 5383419437 4400835611 4101982754 1519595961 5245792592 361617983 2749618781 1961362420 6071049745 3218074367 883237862 766782110 1284574799 1163029746 1829051469 1302409327 2105572087 1587995436 2901202...
output:
394 393 396 395 397 398 400 399 385 386 387 388 389 390 391 392 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 ...
result:
ok 8 lines
Test #12:
score: 5
Accepted
time: 0ms
memory: 5920kb
input:
8 11 571 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
1960 1995 2047 1968 1956 2044 2000 2004 2041 1942 1955 2028 2037 2036 1964 1938 1952 2032 1941 1971 1957 2006 1932 1989 1928 1950 2023 1922 2021 1978 1992 1976 2017 2043 1916 1965 1972 1929 1940 1974 1951 1930 1949 1982 1977 1914 1953 1917 1966 1937 1935 1963 1999 1939 1967 1925 2002 1993 1909 1934 ...
result:
ok 8 lines
Test #13:
score: 5
Accepted
time: 2ms
memory: 3928kb
input:
8 11 252 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
1961 1998 2002 1969 2013 2044 1967 2025 1947 1975 2039 1942 2043 2027 2035 2034 1986 2006 2008 1982 2030 1988 2028 1956 1940 1957 2023 1925 1944 1930 1973 1934 2031 1919 1945 1958 2014 2012 1922 1932 2016 1935 1911 1909 2001 1948 1920 2005 2033 2003 1900 1928 1913 1929 2017 1943 1921 2048 1978 1990 ...
result:
ok 8 lines
Test #14:
score: 5
Accepted
time: 3ms
memory: 4012kb
input:
8 11 170392530264 74651887849 17611792511 11288590546 6568520318 11787580396 1038293275 8132485406 811722341 6463339368 5578666288 6988124667 5250658163 7545924747 436981583 4449296950 4837617209 5423956155 3263388134 1290388306 4273188134 2502801698 455787408 2184397509 900391791 934924549 11250348...
output:
1963 2048 2036 2029 2006 2044 2043 1987 1977 2004 1954 2034 1938 2037 1973 2035 1995 2032 1955 1937 2030 2028 1975 1957 1928 1940 2023 1923 1951 1947 1981 1941 1992 1965 2007 2002 2013 2012 1934 2009 1909 1916 2045 2011 2040 2041 1922 1921 1927 2000 1924 1968 1997 2033 1996 1994 1964 1943 2019 1901 ...
result:
ok 8 lines
Test #15:
score: 5
Accepted
time: 2ms
memory: 3932kb
input:
8 11 10817060597 85858621967 47769507919 2550569053 4936407038 4200947363 15181090532 2195335264 1279109336 9430376850 3667617132 2581310809 1530224542 7058648206 133323350 150591857 3490174463 5246064700 5403826000 616788461 4805350827 2971535312 1549457606 1430948590 1859856676 2761221467 10782807...
output:
679 772 801 723 707 751 891 945 745 807 775 795 726 746 815 1083 694 846 739 1287 702 763 714 842 699 767 879 715 716 861 769 857 709 802 719 720 721 734 864 877 727 809 733 898 732 762 752 782 737 824 738 788 766 935 773 774 753 840 760 832 768 808 811 957 743 1062 917 1023 765 771 781 862 744 889 ...
result:
ok 8 lines
Test #16:
score: 5
Accepted
time: 110ms
memory: 6228kb
input:
17 16 185467288814 92060578373 47290795643 9286036925 9228394756 4811881952 8646592030 8944909812 2841304722 6070010500 6008789791 6082937518 4490550145 5615562853 6824949729 4377456320 5710382139 2189154879 2907374836 4635243843 815487121 3594634884 1123206624 3451101389 1464409182 3816376047 99149...
output:
65536 65535 65534 65533 65532 65531 65530 65529 65528 65527 65526 65525 65524 65523 65522 65521 65520 65519 65518 65517 65516 65515 65514 65513 65512 65511 65510 65509 65508 65507 65506 65505 65504 65503 65502 65501 65500 65499 65498 65497 65496 65495 65494 65493 65492 65491 65490 65489 65488 65487 ...
result:
ok 17 lines
Test #17:
score: 5
Accepted
time: 113ms
memory: 6232kb
input:
17 16 8329 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
65444 65489 65480 65475 65464 65476 65518 65487 65529 65528 65527 65478 65453 65486 65446 65522 65470 65434 65429 65501 65517 65516 65471 65431 65433 65436 65443 65472 65425 65424 65507 65417 65505 65504 65428 65460 65449 65488 65437 65432 65500 65404 65495 65503 65494 65492 65491 65391 65438 65511 ...
result:
ok 17 lines
Test #18:
score: 5
Accepted
time: 114ms
memory: 6220kb
input:
17 16 15956 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
65448 65536 65535 65467 65533 65532 65443 65530 65529 65468 65527 65433 65525 65524 65474 65519 65494 65460 65430 65459 65482 65523 65516 65514 65445 65512 65500 65455 65431 65444 65507 65407 65526 65463 65462 65502 65511 65501 65499 65515 65498 65520 65521 65395 65510 65496 65488 65428 65465 65425 ...
result:
ok 17 lines
Test #19:
score: 5
Accepted
time: 113ms
memory: 6220kb
input:
17 16 123563911790 35459655441 43632569067 27856417624 17183249762 11408415432 6410374431 4355108219 10839722895 1557427267 8039957610 3261023448 863292515 2321876702 4529787424 6094181663 5552293666 1229609052 3243632422 3258596121 2777539196 218149318 857735919 4190629450 13122153 235727176 405797...
output:
65449 65483 65462 65496 65533 65502 65471 65480 65434 65528 65459 65428 65525 65524 65519 65536 65470 65466 65430 65520 65461 65444 65515 65441 65477 65512 65494 65500 65509 65487 65499 65406 65475 65504 65532 65418 65510 65403 65468 65409 65443 65497 65511 65425 65522 65427 65421 65508 65495 65489 ...
result:
ok 17 lines
Test #20:
score: 5
Accepted
time: 111ms
memory: 6108kb
input:
17 16 2433509850 94402852594 4739314371 10807842811 23113510462 3844106361 15285318548 11429331314 4513086672 6976145076 7406862331 3902969782 4483098352 4142852842 6501115945 6642627273 3048275771 3986632722 890509821 3063792232 3653510136 2720826892 1129556719 655572505 3248045315 2596327240 19596...
output:
3163 3042 2994 3028 3056 3044 3005 2992 3115 2968 2986 3007 2972 3003 3152 2987 2957 3000 3060 3202 3081 3154 2977 3165 3055 2999 3069 3225 3144 2975 2988 3140 3223 2959 2966 3038 2971 2985 2945 2998 3021 2942 2939 2936 2965 3067 3173 3017 2933 3012 2956 3118 2960 2961 2962 3082 3142 3016 2967 2950 ...
result:
ok 17 lines