QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#867667 | #9685. nim 游戏 | lgvc | 12 | 940ms | 56100kb | C++23 | 4.5kb | 2025-01-23 21:10:37 | 2025-01-23 21:10:38 |
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 21:10:37]
- 提交
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[100009],b[100009],vf[100009],ss,p[62][100009];
struct n_t{
int a,b;
};
std::vector<n_t> t[20009];
int ct,tx;
int qr(std::vector<n_t> tq) {
int as=ss;
for(int i=0;i<tq.size();i++) {
as^=a[tq[i].a];
as^=(a[tq[i].a]+tq[i].b);
}
return as;
}
inline bool cmp(n_t x,n_t y) {
return x.a<y.a;
}
inline bool fd(int x,std::vector<n_t> y) {
for(int i=0;i<y.size();i++) {
if(y[i].a==x) return 1;
}
return 0;
}
int vc(std::vector<n_t> tq) {
tx++;
for(int i=0;i<tq.size();i++) vf[tq[i].a]=tx;
return tx;
}
int sv(std::vector<n_t> tq) {
int aq=0;
int ti=vc(tq);
for(int i=60;i>=0;i--) {
if((qr(tq)>>i)&1) {
bool zt=0;
for(int j=1;j<=N;j++) {
int t=p[i][j];
if((a[t]>>i)%2==0) {
if(vf[t]==ti) continue;
int x=(a[t]&((1ll<<i)-1));
aq+=(1ll<<i)-x;
tq.push_back((n_t){t,(1ll<<i)-x});
vf[t]=ti;
zt=1;
break;
} else {
break;
}
}
if(!zt) {
for(int j=0;j<tq.size();j++) {
int x=tq[j].b+a[tq[j].a];
if(x&((1ll<<i+1)-1)) continue;
tq[j].b+=(1ll<<i);
zt=1;
break;
}
if(!zt) {
return (1ll<<62);
}
}
}
}
return aq;
}
std::unordered_map<int,int> vi;
void cl(std::vector<n_t> tq) {
if(ct==M) return;
std::sort(tq.begin(),tq.end(),cmp);
int vm=tq.size();
for(int j=0;j<tq.size();j++) {
vm=(vm*137+tq[j].a)%10000000000000061ll;
vm=(vm*137+tq[j].b)%10000000000000061ll;
}
if(vi[vm]) return;
vi[vm]=1;
ct++;
t[ct]=tq;
}
bool qj(int i,std::vector<n_t> tq,int va) {
if(va!=sv(tq)) return 0;
if(i==-1) {
cl(tq);
return 1;
}
if((qr(tq)>>i)&1) {
//if(i==0) printf("!!!\n");
int ans=(1ll<<61);
for(int j=1;j<=N;j++) {
int t=p[i][j];
if(fd(t,tq)) continue;
if((a[t]>>i)%2==0) {
// assert(t);
int x=(a[t]&((1ll<<i)-1));
tq.push_back((n_t){t,(1ll<<i)-x});
if(!qj(i-1,tq,va-(1ll<<i)+x)) return 1;
tq.pop_back();
if(ct==M) return 1;
} else break;
}
for(int j=0;j<tq.size();j++) {
int x=tq[j].b+a[tq[j].a];
if(x&((1ll<<i+1)-1)) continue;
tq[j].b+=(1ll<<i);
if(!qj(i-1,tq,va-(1ll<<i))) return 1;
if(ct==M) return 1;
tq[j].b-=(1ll<<i);
}
} else {
qj(i-1,tq,va);
}
return 1;
}
#define INF_LL 0x3f3f3f3f3f3f3f3f
int tp;
bool cmq(int x,int y) {
x=a[x];
y=a[y];
if(((x^y)>>tp)&1)
return (x&((1ll<<tp+1)-1))<(y&((1ll<<tp+1)-1));
return (x&((1ll<<tp)-1))>(y&((1ll<<tp)-1));
}
signed main(void) {
C=read();T=read();
while(T--) {
vi.clear();
N=read();M=read();
ct=0;
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;
}
for(int i=0;i<=60;i++) {
for(int j=1;j<=N;j++) p[i][j]=j;
tp=i;
std::sort(p[i]+1,p[i]+N+1,cmq);
}
std::vector<n_t> tq;
int ans=sv(tq);
for(int i=0;i<=60;i++) {
std::vector<n_t> tq;
if(ss>=(1ll<<i+1)) continue;
int t=p[i][1];
if((a[t]>>i)&1) continue;
int x=(a[t]&((1ll<<i)-1));
tq.push_back((n_t){t,(1ll<<i)-x});
ans=std::min(ans,sv(tq)+(1ll<<i)-x);
}
qj(60,tq,ans);
for(int i=0;i<=60;i++) {
if(ct==M) break;
if(ss>=(1ll<<i+1)) continue;
std::vector<n_t> tq;
for(int j=1;j<=N;j++) {
int t=p[i][j];
if((a[t]>>i)&1) break;
int x=(a[t]&((1ll<<i)-1));
tq.push_back((n_t){t,(1ll<<i)-x});
if(!qj(i,tq,ans-(1ll<<i)+x)) break;
if(ct==M) break;
tq.pop_back();
}
}
// qj(60,tq,ans);
printf("%lld\n%lld\n",ans,ct);
for(int i=1;i<=ct;i++) {
printf("%lld\n",(int)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: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 867ms
memory: 55232kb
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:
212773591 0 232215735 0 258455165 0 9680988 0 468500191 0 119331212 0 182013137 0 340682912 0 69282083 0 41166609 0 45382862 0 526933894 0 124188898 0 179146009 0 20180789 0 102641402 0 204324144 0 317921922 0 505059782 0 6443005 0 211921215 0 445355113 0 73618341 0 175349252 0 483064943 0 4752546 0...
result:
wrong answer jury has worse answer? check your output.
Subtask #2:
score: 12
Accepted
Test #2:
score: 12
Accepted
time: 1ms
memory: 55120kb
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: 12
Accepted
time: 0ms
memory: 55128kb
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 8 3 1 2 5 2 3 3 3 2 4 5 3 2 3 2 2 5 3 5 2 2 5 5 3 3 1 2 5 4 1 3 3 2 4 5 1 4 3 2 2 5 1 7 2 2 5 7 1 2 4 2 1 5 1 1 2 3 5 1 1 2 4 5 1 1 1 5 2 10 13 3 1 2 4 2 1 7 3 1 3 4 2 1 7 2 1 4 2 8 2 1 4 3 7 2 1 4 ...
result:
ok correct answer
Test #4:
score: 12
Accepted
time: 2ms
memory: 55124kb
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 5 2 1 5 1 1 2 2 5 1 1 2 4 5 1 1 1 5 2 1 1 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:
ok correct answer
Subtask #3:
score: 0
Wrong Answer
Dependency #2:
100%
Accepted
Test #5:
score: 0
Wrong Answer
time: 1ms
memory: 55124kb
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 20 5 1 2 3 4 6 1 19 1 1 124 4 2 3 4 6 19 1 1 125 4 2 3 4 6 20 1 1 124 4 2 3 4 6 19 1 2 124 4 2 3 4 6 19 2 1 124 4 1 2 4 6 2 19 1 124 3 2 4 6 19 1 126 3 2 4 6 21 1 124 3 2 4 6 19 3 124 5 1 2 3 5 6 1 19 1 1 124 4 2 3 5 6 19 1 1 125 4 2 3 5 6 20 1 1 124 4 2 3 5 6 19 1 2 124...
result:
wrong answer jury has worse answer? check your output.
Subtask #4:
score: 0
Wrong Answer
Test #8:
score: 0
Wrong Answer
time: 376ms
memory: 55748kb
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 4330 6806 12450 15412 16083 20338 30949 31755 45139 48217 59387 59608 74711 1048576 262144 33554432 16384 8 2048 2 512 4096 16 64 65536 268435456 13 4330 6806 12450 15412 16083 20338 31755 45139 48217 59387 59608 74711 86656 1048576 262144 33554432 16384 8 2048 512 4096 16 64 655...
result:
wrong answer jury has worse answer? check your output.
Subtask #5:
score: 0
Wrong Answer
Test #18:
score: 0
Wrong Answer
time: 940ms
memory: 56100kb
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:
536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 536870912 0 ...
result:
wrong answer jury has worse answer? check your output.
Subtask #6:
score: 0
Wrong Answer
Test #22:
score: 0
Wrong Answer
time: 4ms
memory: 55016kb
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 134 203 349 355 565 569 673 786 876 955 996 999 5 2638 1 9 531 1 1 697 251113 10 5226 3995 12 134 203 349 355 542 565 673 786 876 955 996 999 5 2638 1 9 1 531 1 697 251113 10 5226 3995 12 134 203 349 355 543 565 673 786 876 955 996 999 5 2638 1 9 1 531 1 697 251113 10 5226 3995 12...
result:
wrong answer jury has worse answer? check your output.
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #7:
0%
Subtask #9:
score: 0
Skipped
Dependency #8:
0%