QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#867428 | #9685. nim 游戏 | lgvc# | 36 | 1371ms | 14836kb | C++23 | 4.0kb | 2025-01-23 15:55:35 | 2025-01-23 15:55:36 |
Judging History
你现在查看的是最新测评结果
- [2025-01-27 09:19:35]
- hack成功,自动添加数据
- (/hack/1490)
- [2025-01-27 08:19:11]
- hack成功,自动添加数据
- (/hack/1488)
- [2025-01-26 18:55:44]
- hack成功,自动添加数据
- (/hack/1475)
- [2025-01-23 15:55:35]
- 提交
answer
#include <bits/stdc++.h>
#define int long long
static char buf[1000000],*paa=buf,*pd=buf;
static char buf2[1000000],*pp=buf2;
#define getchar() paa==pd&&(pd=(paa=buf)+fread(buf,1,1000000,stdin),paa==pd)?EOF:*paa++
inline void pc(char ch){
if(pp-buf2==1000000) fwrite(buf2,1,1000000,stdout),pp=buf2;
*pp++=ch;
}
inline void pcc(){
fwrite(buf2,1,pp-buf2,stdout);
pp=buf2;
}
inline int read(void){
int w=1;
register int x(0);register char c(getchar());
while(c<'0'||c>'9'){if(c=='-') w=-1;c=getchar();}
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
return w*x;
}
void write(int x){
static int sta[20];
int top=0;
do{
sta[top++]=x%10,x/=10;
}while(x);
while(top) pc(sta[--top]+48);
}
void we(int x){
write(x);
pc('\n');
}
int C,T,N,M,a[1000009],b[1000009],c[1000009];
#define LL long long
LL sv() {
LL aq=0;
for(int i=1;i<=N;i++) c[i]=a[i];
for(int i=60;i>=0;i--) {
bool ff=0;
int ss=0;
for(int j=1;j<=N;j++) {
if((a[j]>>i)&1) ff^=1;
ss^=a[j];
}
if(ff) {
int ans=(1ll<<61);
for(int j=1;j<=N;j++) {
if((a[j]>>i)%2==0) {
int x=(a[j]&((1ll<<i)-1));
ans=std::min(ans,(1ll<<i)-x);
}
}
if(ans==(1ll<<61)) {
for(int i=1;i<=N;i++) a[i]=c[i];
return (1ll<<62)-1;
}
for(int j=1;j<=N;j++) {
if((a[j]>>i)%2==0) {
int x=(a[j]&((1ll<<i)-1));
if(ans==(1ll<<i)-x) {
a[j]+=(1ll<<i)-x;
aq+=(1ll<<i)-x;
break;
}
}
}
}
}
for(int i=1;i<=N;i++) a[i]=c[i];
return aq;
}
struct n_t{
int a,b;
};
std::unordered_map<int,int> vi;
std::vector<n_t> t[10009];
int ct;
void cl() {
if(ct==M) return;
int vm=0;
for(int j=1;j<=N;j++) {
vm=(vm*137+a[j])%10000000000000061ll;
}
if(vi[vm]) return;
vi[vm]=1;
ct++;
for(int j=1;j<=N;j++) {
if(a[j]!=b[j]) {
t[ct].push_back((n_t){j,a[j]-b[j]});
}
}
}
void qj(int i,LL va) {
if(i==-1) {
cl();
return;
}
if(va!=sv()) return;
LL aq=0;
bool ff=0;
int ss=0;
for(int j=1;j<=N;j++) {
if((a[j]>>i)&1) ff^=1;
ss^=a[j];
}
if(ff) {
int ans=(1ll<<61);
for(int j=1;j<=N;j++) {
if((a[j]>>i)%2==0) {
int x=(a[j]&((1ll<<i)-1));
ans=std::min(ans,(1ll<<i)-x);
}
}
for(int j=1;j<=N;j++) {
if((a[j]>>i)%2==0) {
int x=(a[j]&((1ll<<i)-1));
if(ans!=(1ll<<i)-x) continue;
a[j]+=(1ll<<i)-x;
qj(i-1,va-(1ll<<i)+x);
if(ct==M) return;
a[j]-=(1ll<<i)-x;
}
}
} else {
qj(i-1,va);
}
if(ct==M) return;
}
#define INF_LL 0x3f3f3f3f3f3f3f3f
signed main(void) {
C=read();T=read();
while(T--) {
vi.clear();
N=read();M=read();
ct=0;
int ss=0;
for(int i=1;i<=N;i++) {
a[i]=read();
b[i]=a[i];
ss^=a[i];
}
if(ss==0) {
printf("0\n1\n0\n\n\n");
continue;
}
long long ans=(1ll<<62)-1;
for(int j=60;j>=0;j--) {
if(ss>=(1ll<<j+1)) continue;
int as=(1ll<<60)-1;
for(int i=1;i<=N;i++) {
if(((a[i]>>j)&1)==0) {
int vv=(a[i]&((1ll<<j)-1));
as=std::min(as,(1ll<<j)-vv);
}
}
for(int i=1;i<=N;i++) {
if(((a[i]>>j)&1)==0) {
int vv=(a[i]&((1ll<<j)-1));
if(as==(1ll<<j)-vv) {
a[i]+=(1ll<<j)-vv;
ans=std::min(ans,sv()+(1ll<<j)-vv);
a[i]-=(1ll<<j)-vv;
break;
}
}
}
}
qj(60,ans);
// for(int j=60;j>=0;j--) {
// if(ss>=(1ll<<j+1)) continue;
/// int as=(1ll<<60)-1;
// for(int i=1;i<=N;i++) {
// if(((a[i]>>j)&1)==0) {
// int vv=(a[i]&((1ll<<j)-1));
// as=std::min(as,(1ll<<j)-vv);
// }
// }
// for(int i=1;i<=N;i++) {
// if(((a[i]>>j)&1)==0) {
// int vv=(a[i]&((1ll<<j)-1));
// a[i]+=(1ll<<j)-vv;
// qj(60,ans-(1ll<<j)+vv);
// a[i]-=(1ll<<j)-vv;
// }
// }
// if(ct==M) break;
// }
printf("%lld\n%lld\n",ans,ct);
for(int i=1;i<=ct;i++) {
printf("%lld\n",t[i].size());
for(int j=0;j<t[i].size();j++) printf("%lld ",t[i][j].a);
printf("\n");
for(int j=0;j<t[i].size();j++) printf("%lld ",t[i][j].b);
printf("\n");
t[i]=t[0];
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 130ms
memory: 10092kb
input:
1 10000 2 1 324097321 555675086 2 1 304655177 991244276 2 1 9980291 383616352 2 1 1071036550 795625380 2 1 682098056 68370721 2 1 969101726 685975156 2 1 973896269 354857775 2 1 196188000 606494155 2 1 754416123 467588829 2 1 495704303 558090120 2 1 618002000 491488050 2 1 741575237 9937018 2 1 1002...
output:
231577765 1 1 1 231577765 686589099 1 1 1 686589099 373636061 1 1 1 373636061 275411170 1 1 2 275411170 613727335 1 1 2 613727335 283126570 1 1 2 283126570 619038494 1 1 2 619038494 410306155 1 1 1 410306155 286827294 1 1 2 286827294 62385817 1 1 1 62385817 126513950 1 1 2 12651...
result:
ok correct answer
Subtask #2:
score: 6
Acceptable Answer
Test #2:
score: 12
Accepted
time: 1ms
memory: 9936kb
input:
2 5 5 2000 0 13 3 4 10 5 2000 0 3 9 1 11 5 2000 0 13 7 3 5 5 2000 0 1 13 9 2 5 2000 0 8 14 7 13
output:
0 1 0 0 1 0 2 2 2 2 3 1 1 2 3 5 1 1 3 2 2 1 5 1 2 1 5 3 2 1 2 4 5 1 1
result:
ok correct answer
Test #3:
score: 6
Acceptable Answer
time: 0ms
memory: 10068kb
input:
2 5 5 2000 0 4 14 5 7 5 2000 0 2 15 0 12 5 2000 0 1 14 0 5 5 2000 0 13 4 12 3 5 2000 0 10 10 1 11
output:
6 2 3 1 4 5 4 1 1 2 4 5 1 5 1 4 1 1 1 1 2 1 1 4 1 1 5 1 8 4 3 1 2 5 2 3 3 2 2 5 5 3 3 2 4 5 3 2 3 2 2 5 3 5 2 4 2 1 5 1 1 2 3 5 1 1 2 4 5 1 1 1 5 2 10 8 2 1 4 3 7 3 1 2 4 2 1 7 3 1 3 4 2 1 7 2 1 4 2 8 2 1 4 1 9 2 2 4 1 9 2 3 4 1 9 1 4 10
result:
points 0.5 right answer but not right solutions at 5th solution
Test #4:
score: 6
Acceptable Answer
time: 0ms
memory: 9944kb
input:
2 5 5 2000 0 6 15 10 1 5 2000 0 15 0 13 10 5 2000 0 5 7 5 1 5 2000 0 13 3 2 15 5 2000 0 2 4 7 0
output:
2 4 2 1 5 1 1 2 2 5 1 1 2 4 5 1 1 1 5 2 8 2 1 1 8 1 3 8 4 2 2 2 5 1 3 2 4 5 1 3 1 1 1 2 1 1 4 1 1 1 1 2 1 1 3 1 1 5 1
result:
points 0.5 right answer but not right solutions at 1th solution
Subtask #3:
score: 6
Acceptable Answer
Dependency #2:
50%
Acceptable Answer
Test #5:
score: 6
Acceptable Answer
time: 1ms
memory: 10072kb
input:
3 5 6 2000 0 45 517 811 107 132 6 2000 0 382 576 805 419 579 6 2000 0 379 809 441 331 67 6 2000 0 565 776 959 852 383 6 2000 0 613 383 829 47 441
output:
146 10 5 1 2 3 4 6 1 19 1 1 124 4 2 3 4 6 20 1 1 124 4 2 3 4 6 19 2 1 124 4 2 3 4 6 19 1 2 124 4 2 3 4 6 19 1 1 125 5 1 2 3 5 6 1 19 1 1 124 4 2 3 5 6 20 1 1 124 4 2 3 5 6 19 2 1 124 4 2 3 5 6 19 1 2 124 4 2 3 5 6 19 1 1 125 179 625 4 1 4 5 6 30 27 93 29 5 1 3 4 5 6 28 2 27 93...
result:
points 0.5 right answer but not right solutions at 4th solution
Test #6:
score: 6
Acceptable Answer
time: 1ms
memory: 10072kb
input:
3 5 6 2000 0 75 173 555 637 905 6 2000 0 934 118 906 367 728 6 2000 0 244 321 598 625 469 6 2000 0 573 489 24 480 459 6 2000 0 424 356 750 623 871
output:
557 125 5 1 2 3 5 6 11 53 339 131 23 5 1 2 3 5 6 10 54 339 131 23 5 1 2 3 5 6 10 53 340 131 23 5 1 2 3 5 6 10 53 339 132 23 5 1 2 3 5 6 10 53 339 131 24 5 1 2 3 5 6 9 55 339 131 23 5 1 2 3 5 6 8 56 339 131 23 5 1 2 3 5 6 8 55 340 131 23 5 1 2 3 5 6 8 55 339 132 23 5 1 2 3 5 6 8 55...
result:
points 0.5 right answer but not right solutions at 4th solution
Test #7:
score: 6
Acceptable Answer
time: 2ms
memory: 10068kb
input:
3 5 6 2000 0 886 972 226 813 407 6 2000 0 219 190 742 101 572 6 2000 0 590 423 516 1017 46 6 2000 0 388 807 207 205 647 6 2000 0 408 180 238 300 694
output:
176 25 5 1 2 4 5 6 12 10 30 19 105 5 1 2 4 5 6 8 14 30 19 105 5 1 2 4 5 6 8 10 34 19 105 5 1 2 4 5 6 8 10 30 23 105 5 1 2 4 5 6 8 10 30 19 109 5 1 2 4 5 6 4 18 30 19 105 4 2 4 5 6 22 30 19 105 4 2 4 5 6 18 34 19 105 4 2 4 5 6 18 30 23 105 4 2 4 5 6 18 30 19 109 5 1 2 4 5 6 4 10 ...
result:
points 0.5 right answer but not right solutions at 4th solution
Subtask #4:
score: 0
Time Limit Exceeded
Test #8:
score: 6
Acceptable Answer
time: 1069ms
memory: 12580kb
input:
4 257 100000 100 32768 65536 262144 32768 8388608 1048576 4 67108864 16384 32768 262144 8192 512 134217728 65536 4194304 262144 67108864 1024 262144 64 32 65536 2097152 268435456 1 2048 4194304 16777216 8 16384 2 2048 16777216 268435456 262144 1048576 8388608 16 268435456 2 128 4194304 262144 32768 ...
output:
303389274 100 13 2 3 6 9 13 21 25 27 30 32 39 62 66 65536 262144 1048576 16384 512 64 268435456 2048 8 2 16 4096 33554432 13 2 3 6 9 13 21 25 27 30 39 41 62 66 65536 262144 1048576 16384 512 64 268435456 2048 8 16 2 4096 33554432 13 2 3 6 9 13 21 25 27 30 39 62 66 105 65536 262144 1048576 16384...
result:
points 0.5 right answer but not right solutions at 249th solution
Test #9:
score: 6
Acceptable Answer
time: 827ms
memory: 13528kb
input:
4 266 100000 100 134217728 524288 8388608 4 8 8388608 33554432 4 536870912 4 16 8 33554432 33554432 256 65536 8 16 64 8 256 2048 268435456 256 8192 2 1024 65536 32 2048 134217728 8 1048576 8 16777216 33554432 1024 33554432 131072 16 2 33554432 8192 512 4194304 2048 268435456 256 536870912 16777216 1...
output:
269988539 100 15 5 11 16 23 25 26 29 33 39 44 61 65 71 95 121 8 16 65536 268435456 8192 2 32 1048576 131072 512 262144 128 1 32768 4096 15 5 11 16 23 25 26 29 33 39 44 61 65 95 121 132 8 16 65536 268435456 8192 2 32 1048576 131072 512 262144 128 32768 4096 1 15 5 11 16 23 25 26 29 33 39 44 61 65...
result:
points 0.5 right answer but not right solutions at 266th solution
Test #10:
score: 6
Acceptable Answer
time: 1059ms
memory: 13364kb
input:
4 269 100000 100 1048576 2 64 67108864 1024 67108864 268435456 32768 8388608 32 256 2 268435456 262144 524288 262144 2 524288 64 8192 262144 536870912 2097152 64 1024 2 1048576 128 2 8388608 512 32768 1 8388608 4 2 268435456 128 67108864 65536 2 8388608 2048 16 2048 4096 32768 1048576 32768 32 83886...
output:
471323918 100 15 1 2 4 5 7 8 11 14 35 40 46 53 61 74 114 1048576 2 67108864 1024 268435456 32768 256 262144 4 65536 4096 131072 8 16384 134217728 15 1 4 5 7 8 11 12 14 35 40 46 53 61 74 114 1048576 67108864 1024 268435456 32768 256 2 262144 4 65536 4096 131072 8 16384 134217728 15 1 4 5 7 8 11 1...
result:
points 0.5 right answer but not right solutions at 268th solution
Test #11:
score: 0
Time Limit Exceeded
input:
4 2 100000 5000 32768 2 1024 1 65536 32768 4194304 4 2 33554432 1048576 268435456 4194304 268435456 268435456 4194304 32768 2097152 131072 16777216 1024 262144 2048 65536 512 1024 8388608 128 512 33554432 1 32 134217728 8388608 2097152 4 2097152 1048576 1024 33554432 536870912 536870912 33554432 327...
output:
result:
Subtask #5:
score: 12
Accepted
Test #18:
score: 12
Accepted
time: 533ms
memory: 10588kb
input:
5 10000 10 1 0 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 10 1 0 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 10 1 0 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741...
output:
1073741823 1 1 1 1073741823 1073741823 1 1 1 1073741823 1073741823 1 1 1 1073741823 1073741823 1 1 1 1073741823 1073741823 1 1 1 1073741823 1073741823 1 1 1 1073741823 1073741823 1 1 1 1073741823 1073741823 1 1 1 1073741823 1073741823 1 1 1 1073741823 1073741823 1 1 1 1073741823 ...
result:
ok correct answer
Test #19:
score: 12
Accepted
time: 1371ms
memory: 13732kb
input:
5 2323 100000 1 0 3170633 888529329 347839787 101667249 273239696 1028446182 411994109 710973319 298677951 299452068 519308796 361451040 488605068 74238166 997794448 478367019 532094220 747266199 217905213 682359917 774814810 234838947 456387659 38459020 434013070 633290806 173828476 94076883 568288...
output:
11962 1 15 4 10 88 212 523 954 2474 5529 5764 8448 33798 38129 47454 49541 78515 1 1 1 1 1 1 1 19 1 54 8212 139 1 2165 1364 1607036 1 11 4 6 7 12 15 16 22 25 26 28 29 65471 32512 6 520064 978944 6136 3836 1 4 60 2 106 1 3 1 2 3 41 20 45 3 1 2 1 2 1 2 126 1 5 1 3 5 9 10 1 12 7 60 46 727 1 6...
result:
ok correct answer
Test #20:
score: 12
Accepted
time: 1362ms
memory: 13732kb
input:
5 2205 100000 1 0 684191025 220215685 982495864 602362406 687396179 439432236 81065680 398068897 269754402 306183653 309939439 664994998 1011962742 338161922 629593565 926305057 1026259775 711874360 69406110 426672919 208267066 551253027 9384823 26156203 778817402 654214308 527029151 1065024353 2870...
output:
22539 1 18 1 2 6 21 79 252 901 1463 3023 8561 9642 11813 14681 21599 38540 38873 89268 92825 1 1 1 1 1 1 1 1 1 1 18405 5 1 2826 14 846 404 28 5296170 1 10 3 8 9 11 12 16 19 20 30 38 2 1048320 64 4194240 30 6142 31744 15360 16 252 2997548 1 3 3 4 5 7998 1031664 1957886 10 1 2 1 5 2 8 73171 1 ...
result:
ok correct answer
Test #21:
score: 12
Accepted
time: 1343ms
memory: 14836kb
input:
5 2166 100000 1 0 58930516 543560994 783997157 728082180 789115629 549794748 81818067 214839912 203394814 711969322 908524000 570262778 992867922 359455295 88035653 412186516 937931728 331800409 545354553 535440658 894562512 657466952 555070606 469471475 1055263866 874958292 76960239 478302168 68009...
output:
8241 1 16 1 4 28 66 72 394 473 709 1894 26786 29190 33285 54258 68234 72809 82425 1 1 1 63 1 1 1 1 1 5 7798 1 156 192 4 14 2846999 1 4 1 2 4 5 202000 103522 1978946 562531 1605 1 6 1 2 6 7 8 12 1 1 96 4 1023 480 21150 1 4 1 2 3 5 47 13205 4050 3848 13 1 2 1 2 7 6 0 1 0 1667525 1 7 1 3 12...
result:
ok correct answer
Subtask #6:
score: 8
Acceptable Answer
Test #22:
score: 8
Acceptable Answer
time: 11ms
memory: 10068kb
input:
6 23 1000 10 0 357293452 452461848 986047039 546588280 762710079 767831017 39741545 416114273 515599366 1018969624 603342125 928112286 1053016142 240953466 533088067 1028134429 504727014 371307863 834428873 968387878 478550336 1047217797 1046651542 777749850 866989319 92995163 251915198 363285573 10...
output:
264227 10 12 1 19 134 203 355 565 673 786 876 955 996 999 1 1 5 2638 9 531 1 697 251113 10 5226 3995 12 2 19 134 203 355 565 673 786 876 955 996 999 1 1 5 2638 9 531 1 697 251113 10 5226 3995 12 3 19 134 203 355 565 673 786 876 955 996 999 1 1 5 2638 9 531 1 697 251113 10 5226 3995 12 5 19 134...
result:
points 0.5 right answer but not right solutions at 14th solution
Test #23:
score: 8
Acceptable Answer
time: 11ms
memory: 10032kb
input:
6 23 1000 10 0 978686021 287986921 276311856 889616598 739968417 1060147652 463275477 172393699 591333230 983197307 235514434 330494755 449056272 882229818 781111474 275587745 980041928 334198691 305313012 415758352 947298893 950211162 909723054 961622596 917454340 161928901 404346316 369133631 1038...
output:
709905 10 15 2 9 29 32 77 279 283 482 656 677 727 842 917 977 978 1 1 1 56 1 3862 6 12836 4 1 47 693086 1 1 1 15 3 9 29 32 77 279 283 482 656 677 727 842 917 977 978 1 1 1 56 1 3862 6 12836 4 1 47 693086 1 1 1 15 6 9 29 32 77 279 283 482 656 677 727 842 917 977 978 1 1 1 56 1 3862 6 12836 4 1 4...
result:
points 0.5 right answer but not right solutions at 12th solution
Test #24:
score: 16
Accepted
time: 13ms
memory: 9940kb
input:
6 15 1000 10 0 631723071 149784582 965844254 515554472 887253148 467825521 981769969 1054193550 627909969 590277818 159342752 658063143 667914173 169490051 25536270 337269419 1056885019 980490575 750858271 553446484 347553447 376197986 1053224035 473470890 123586 97769047 761755924 510998818 2560945...
output:
737485 10 15 7 13 15 20 172 265 384 474 599 625 747 790 831 880 924 1 1 1 1 27 227 215546 2917 6 7 87404 1600 16 41649 388082 15 8 13 15 20 172 265 384 474 599 625 747 790 831 880 924 1 1 1 1 27 227 215546 2917 6 7 87404 1600 16 41649 388082 15 10 13 15 20 172 265 384 474 599 625 747 790 831 880...
result:
ok correct answer
Test #25:
score: 8
Acceptable Answer
time: 11ms
memory: 9948kb
input:
6 25 1000 10 0 751950140 901599329 987895071 306253500 278530668 539473653 911723672 948474628 722632384 369217860 428703545 999113214 567923990 53499297 1013528916 263060554 669297221 349021033 832596533 893306880 892438572 345611286 331257977 488113061 578929864 881846255 320356815 76057168 704694...
output:
1119212 10 14 33 97 122 125 215 236 430 431 528 552 576 717 887 950 1 7 5641 1 149775 107 1 6002 26620 674 1237 6239 922903 4 14 35 97 122 125 215 236 430 431 528 552 576 717 887 950 1 7 5641 1 149775 107 1 6002 26620 674 1237 6239 922903 4 14 65 97 122 125 215 236 430 431 528 552 576 717 887 95...
result:
points 0.5 right answer but not right solutions at 8th solution
Test #26:
score: 16
Accepted
time: 9ms
memory: 12108kb
input:
6 2 1000 1 0 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1...
output:
1073741823 1 1 1 1073741823 1073741823 1 1 1 1073741823
result:
ok correct answer
Subtask #7:
score: 0
Time Limit Exceeded
Dependency #3:
50%
Acceptable Answer
Dependency #5:
100%
Accepted
Dependency #6:
50%
Acceptable Answer
Test #27:
score: 0
Time Limit Exceeded
input:
7 195 100000 1000 0 828483622 617711013 242092397 1034026464 456205583 731635466 382894773 533786631 582730039 74863848 661821965 368857719 541353387 662605236 580923280 798012506 54823622 333416217 39292129 995195996 477140985 1014499425 362164396 970752859 879997855 96768859 1005365898 576674982 4...
output:
result:
Subtask #8:
score: 0
Skipped
Dependency #7:
0%
Subtask #9:
score: 0
Skipped
Dependency #8:
0%