QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#20884 | #2492. Hash Function | houzhiyuanakioi | TL | 856ms | 5932kb | C++ | 1.9kb | 2022-02-20 16:48:36 | 2022-05-03 11:49:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
unordered_map<int,long long> mp;
int n,k2=0,k3=0;
bool has=false;
long long t1,t2,t3,h,ans,mod,c2[1<<20],c3[1<<20];
void dfs(int x){
if(has) return;
mp.clear();
long long b=x;
for(int k=0;k<2*n;k+=2) if(x&(1ll<<k)) b^=(1ll<<(2*n-1-k/2));
for(int k=1;k<2*n;k+=2) if(x&(1ll<<k)) b^=(1ll<<((k-1)/2));
long long c=b^(b>>1);
if(b&1) c^=(1ll<<(2*n-1));
long long y=t2;
int j=(1<<k2)-1;
long long hy,hz;
for(;y;y=((y-1)&t2),j--){
hy=(239ll*(((x^y)>>n)<<n)+153ll*(((c^c2[j])>>n)<<n))%mod;
mp[hy]=y;
}
y=j=0;
hy=(239ll*(((x^y)>>n)<<n)+153ll*(((c^c2[j])>>n)<<n))%mod;
mp[hy]=y;
long long z=t3;
j=(1<<k3)-1;
for(;z;z=((z-1)&t3),j--){
hz=(239ll*((x^z)&((1<<n)-1))+153ll*((c^c3[j])&((1<<n)-1)))%mod;
hz=(h+mod-hz)%mod;
if(mp.count(hz)){
has=true;
ans=mp[hz]^x^z;
}
}
z=j=0;
hz=(239ll*((x^z)&((1<<n)-1))+153ll*((c^c3[j])&((1<<n)-1)))%mod;
hz=(h+mod-hz)%mod;
if(mp.count(hz)){
has=true;
ans=mp[hz]^x^z;
}
}
int main(){
scanf("%d%lld",&n,&h);
mod=(1ll<<(2*n-1))-1;
t1=2;
for(int i=0;i<=n-1;i+=2) t1^=(1<<i);
t1|=(1<<n);
t1|=(1ll<<(2*n-2));
for(int i=2*n-1;i>=n+1;i-=2) t1|=(1ll<<i);
t2=0;
for(int i=2*n-4;i>=n+1;i-=2){t2|=(1ll<<i);k2++;}
t3=0;
for(int i=3;i<=n-1;i+=2){t3|=(1ll<<i);k3++;}
for(long long i=t2,j=((1<<k2)-1);i;i=((i-1)&t2),j--){
long long b=i;
for(int k=0;k<2*n;k+=2) if(i&(1ll<<k)) b^=(1ll<<(2*n-1-k/2));
for(int k=1;k<2*n;k+=2) if(i&(1ll<<k)) b^=(1ll<<((k-1)/2));
c2[j]=b^(b>>1);
if(b&1) c2[j]^=(1ll<<(2*n-1));
}
c2[0]=0;
for(long long i=t3,j=((1<<k3)-1);i;i=((i-1)&t3),j--){
long long b=i;
for(int k=0;k<2*n;k+=2) if(i&(1ll<<k)) b^=(1ll<<(2*n-1-k/2));
for(int k=1;k<2*n;k+=2) if(i&(1ll<<k)) b^=(1ll<<((k-1)/2));
c3[j]=b^(b>>1);
if(b&1) c3[j]^=(1ll<<(2*n-1));
}
c3[0]=0;
for(long long x=t1;x;x=((x-1)&t1)) dfs(x);
dfs(0);
printf("%lld",ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 5732kb
input:
4 83
output:
145
result:
ok good solution
Test #2:
score: 0
Accepted
time: 8ms
memory: 5736kb
input:
10 497091
output:
548470
result:
ok good solution
Test #3:
score: 0
Accepted
time: 6ms
memory: 5932kb
input:
4 55
output:
234
result:
ok good solution
Test #4:
score: 0
Accepted
time: 856ms
memory: 5764kb
input:
15 444650548
output:
531938370
result:
ok good solution
Test #5:
score: 0
Accepted
time: 346ms
memory: 5788kb
input:
14 114355996
output:
125553692
result:
ok good solution
Test #6:
score: -100
Time Limit Exceeded
input:
16 0