QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#129612 | #56. Nim Product | youngsystem# | 100 ✓ | 877ms | 4344kb | C++20 | 1.5kb | 2023-07-22 21:19:35 | 2023-07-22 21:19:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int n=0,f=1,ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
n=n*10+ch-'0';
ch=getchar();
}
return n*f;
}
int cm[10]={0,1,2,4,16,256,65536};
int mul(int x,int y,int k)
{
if(x==0||y==0)return 0;
if(x==1||y==1)return (x^y^1);
int x1=x/cm[k-1],x2=x%cm[k-1];
int y1=y/cm[k-1],y2=y%cm[k-1];
int cj1=mul(x1,y1,k-1),cj2=mul(x1^x2,y1^y2,k-1),cj3=mul(x2,y2,k-1);
int cj4=mul(cj1,cm[k-1]/2,k-1);
return (cj2^cj3)*cm[k-1]+(cj4^cj3);
}
int cmk[65536];
int dy[65536];
int fastmul(int x,int y)
{
if(x==0||y==0)return 0;
return cmk[(dy[x]+dy[y])%65535];
}
unsigned int SA, SB, SC;
unsigned int rng() {
SA ^= SA << 16;
SA ^= SA >> 5;
SA ^= SA << 1;
unsigned int t = SA;
SA = SB;
SB = SC;
SC ^= t ^ SA;
return SC;
}
int nim_mul(unsigned int x,unsigned int y)
{
int x1=(x>>16),x2=(x&65535);
int y1=(y>>16),y2=(y&65535);
int cj1=fastmul(fastmul(x1,y1),32768),cj2=fastmul(x1^x2,y1^y2),cj3=fastmul(x2,y2);
return ((cj2^cj3)<<16)|(cj1^cj3);
}
int main()
{
cmk[0]=1;
cmk[1]=258;
for(int i=2;i<=65535;i++)
{
cmk[i]=mul(cmk[i-1],258,6);
}
for(int i=0;i<65535;i++)dy[cmk[i]]=i;
int t;
t=read();
SA=read();
SB=read();
SC=read();
unsigned int lastans=0;
for(int greg=1;greg<=t;greg++)
{
unsigned int x=rng()+lastans;
unsigned int y=rng();
lastans=nim_mul(x,y);
//printf("%u %u %u\n",x,y,lastans);
}
printf("%u\n",lastans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 25
Accepted
time: 14ms
memory: 4116kb
input:
10 274134852 279286565 744539633
output:
2002382043
result:
ok single line: '2002382043'
Test #2:
score: 25
Accepted
time: 14ms
memory: 4168kb
input:
1000 734766235 309378503 610268282
output:
2106551671
result:
ok single line: '2106551671'
Test #3:
score: 25
Accepted
time: 15ms
memory: 4344kb
input:
30000 784936363 827067061 800454511
output:
554318281
result:
ok single line: '554318281'
Test #4:
score: 25
Accepted
time: 877ms
memory: 4172kb
input:
30000000 72129929 485897764 129463885
output:
92762235
result:
ok single line: '92762235'