QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#92890 | #56. Nim Product | zsj6315# | 75 | 3ms | 4708kb | C++14 | 1.2kb | 2023-03-31 08:22:19 | 2023-03-31 08:22:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define ull unsigned long long
#define ll long long
#define mod 998244353
#define N 256
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;
}
ull lastans;
ll rem[N][N],r8[1<<8],r16[1<<16];
ull nimP(ull x,ull y,int k=16){
if(x<=1||y<=1)return x*y;
if(k<8&&rem[x][y]>=0)return rem[x][y];
ull a=x>>k,b=y>>k,c=x&((1ull<<k)-1),d=y&((1ull<<k)-1);
ull ab1=nimP(a,b,k>>1),ab;
// ab=nimP(1ull<<k>>1,ab1,k>>1);
if(k==8&&r8[ab1]>=0)ab=r8[ab1];
else if(k==16&&r16[ab1]>=0)ab=r16[ab1];
else {
ab=nimP(1ull<<k>>1,ab1,k>>1);
if(k==8)r8[ab1]=ab;
if(k==16)r16[ab1]=ab;
}
ull cd=nimP(c,d,k>>1);
ull ans=((nimP(a^c,b^d,k>>1)^cd)<<k)^ab^cd;
if(k<8)rem[x][y]=ans;
return ans;
}
int main(){
memset(rem,-1,sizeof rem);
memset(r8,-1,sizeof r8);
memset(r16,-1,sizeof r16);
int T;
scanf("%d%u%u%u",&T,&SA,&SB,&SC);
while(T--){
unsigned int x = rng() + (unsigned int)lastans;
unsigned int y = rng();
lastans = nimP(x, y);
// printf("%u %u %llu\n",x,y,lastans);
}
printf("%llu\n",lastans);
return 0;
}
詳細信息
Test #1:
score: 25
Accepted
time: 2ms
memory: 4708kb
input:
10 274134852 279286565 744539633
output:
2002382043
result:
ok single line: '2002382043'
Test #2:
score: 25
Accepted
time: 3ms
memory: 4708kb
input:
1000 734766235 309378503 610268282
output:
2106551671
result:
ok single line: '2106551671'
Test #3:
score: 25
Accepted
time: 3ms
memory: 4616kb
input:
30000 784936363 827067061 800454511
output:
554318281
result:
ok single line: '554318281'
Test #4:
score: 0
Time Limit Exceeded
input:
30000000 72129929 485897764 129463885