QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#20888 | #2492. Hash Function | houzhiyuanakioi | AC ✓ | 2983ms | 5936kb | C++ | 1.9kb | 2022-02-20 17:49:29 | 2022-05-03 11:50:06 |
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(long long 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-hz;
if(hz<0) 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-hz;
if(hz<0) 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: 0ms
memory: 5860kb
input:
4 83
output:
145
result:
ok good solution
Test #2:
score: 0
Accepted
time: 7ms
memory: 5828kb
input:
10 497091
output:
548470
result:
ok good solution
Test #3:
score: 0
Accepted
time: 3ms
memory: 5880kb
input:
4 55
output:
234
result:
ok good solution
Test #4:
score: 0
Accepted
time: 751ms
memory: 5872kb
input:
15 444650548
output:
531938370
result:
ok good solution
Test #5:
score: 0
Accepted
time: 288ms
memory: 5872kb
input:
14 114355996
output:
125553692
result:
ok good solution
Test #6:
score: 0
Accepted
time: 316ms
memory: 5728kb
input:
16 0
output:
4146704040
result:
ok good solution
Test #7:
score: 0
Accepted
time: 3ms
memory: 5836kb
input:
3 22
output:
63
result:
ok good solution
Test #8:
score: 0
Accepted
time: 1ms
memory: 5876kb
input:
8 8319
output:
62746
result:
ok good solution
Test #9:
score: 0
Accepted
time: 2ms
memory: 5832kb
input:
12 7629490
output:
15121216
result:
ok good solution
Test #10:
score: 0
Accepted
time: 2ms
memory: 5836kb
input:
2 2
output:
14
result:
ok good solution
Test #11:
score: 0
Accepted
time: 319ms
memory: 5768kb
input:
16 0
output:
4146704040
result:
ok good solution
Test #12:
score: 0
Accepted
time: 316ms
memory: 5796kb
input:
16 0
output:
4146704040
result:
ok good solution
Test #13:
score: 0
Accepted
time: 317ms
memory: 5768kb
input:
16 0
output:
4146704040
result:
ok good solution
Test #14:
score: 0
Accepted
time: 6ms
memory: 5932kb
input:
11 1086647
output:
3757717
result:
ok good solution
Test #15:
score: 0
Accepted
time: 7ms
memory: 5864kb
input:
11 188671
output:
3617165
result:
ok good solution
Test #16:
score: 0
Accepted
time: 8ms
memory: 5740kb
input:
11 2028522
output:
3482225
result:
ok good solution
Test #17:
score: 0
Accepted
time: 77ms
memory: 5764kb
input:
13 23601796
output:
40518521
result:
ok good solution
Test #18:
score: 0
Accepted
time: 3ms
memory: 5732kb
input:
8 29405
output:
42924
result:
ok good solution
Test #19:
score: 0
Accepted
time: 0ms
memory: 5764kb
input:
7 2218
output:
13098
result:
ok good solution
Test #20:
score: 0
Accepted
time: 3ms
memory: 5860kb
input:
7 432
output:
13621
result:
ok good solution
Test #21:
score: 0
Accepted
time: 4ms
memory: 5724kb
input:
11 899191
output:
4131409
result:
ok good solution
Test #22:
score: 0
Accepted
time: 1ms
memory: 5876kb
input:
5 494
output:
281
result:
ok good solution
Test #23:
score: 0
Accepted
time: 3ms
memory: 5876kb
input:
8 13862
output:
51543
result:
ok good solution
Test #24:
score: 0
Accepted
time: 3ms
memory: 5728kb
input:
11 899027
output:
3346232
result:
ok good solution
Test #25:
score: 0
Accepted
time: 3ms
memory: 5828kb
input:
8 7446
output:
53245
result:
ok good solution
Test #26:
score: 0
Accepted
time: 3ms
memory: 5764kb
input:
3 12
output:
54
result:
ok good solution
Test #27:
score: 0
Accepted
time: 3ms
memory: 5876kb
input:
8 6258
output:
58462
result:
ok good solution
Test #28:
score: 0
Accepted
time: 867ms
memory: 5868kb
input:
15 191474555
output:
411455767
result:
ok good solution
Test #29:
score: 0
Accepted
time: 3ms
memory: 5724kb
input:
3 17
output:
28
result:
ok good solution
Test #30:
score: 0
Accepted
time: 824ms
memory: 5880kb
input:
15 161474861
output:
520423443
result:
ok good solution
Test #31:
score: 0
Accepted
time: 2ms
memory: 5868kb
input:
10 180816
output:
869271
result:
ok good solution
Test #32:
score: 0
Accepted
time: 0ms
memory: 5772kb
input:
4 116
output:
246
result:
ok good solution
Test #33:
score: 0
Accepted
time: 2345ms
memory: 5884kb
input:
16 1196684556
output:
1973553583
result:
ok good solution
Test #34:
score: 0
Accepted
time: 528ms
memory: 5936kb
input:
16 1087033358
output:
3403352030
result:
ok good solution
Test #35:
score: 0
Accepted
time: 1213ms
memory: 5864kb
input:
16 2112546660
output:
2823255398
result:
ok good solution
Test #36:
score: 0
Accepted
time: 692ms
memory: 5844kb
input:
16 130507716
output:
3358127644
result:
ok good solution
Test #37:
score: 0
Accepted
time: 2983ms
memory: 5872kb
input:
16 1531459999
output:
1004811660
result:
ok good solution
Test #38:
score: 0
Accepted
time: 422ms
memory: 5724kb
input:
16 1905706077
output:
4053438312
result:
ok good solution
Test #39:
score: 0
Accepted
time: 1592ms
memory: 5880kb
input:
16 1584950777
output:
2565491169
result:
ok good solution
Test #40:
score: 0
Accepted
time: 2316ms
memory: 5880kb
input:
16 1112585098
output:
1917567299
result:
ok good solution
Test #41:
score: 0
Accepted
time: 560ms
memory: 5884kb
input:
16 1527899944
output:
3397200385
result:
ok good solution
Test #42:
score: 0
Accepted
time: 992ms
memory: 5864kb
input:
16 1234237908
output:
2881349673
result:
ok good solution
Test #43:
score: 0
Accepted
time: 362ms
memory: 5932kb
input:
16 922629865
output:
4077846074
result:
ok good solution
Test #44:
score: 0
Accepted
time: 186ms
memory: 5884kb
input:
16 2079610945
output:
4169495274
result:
ok good solution
Test #45:
score: 0
Accepted
time: 1156ms
memory: 5872kb
input:
16 125431469
output:
3184552951
result:
ok good solution
Test #46:
score: 0
Accepted
time: 1629ms
memory: 5796kb
input:
16 425515915
output:
2363405195
result:
ok good solution
Test #47:
score: 0
Accepted
time: 876ms
memory: 5740kb
input:
16 882748949
output:
3504776721
result:
ok good solution
Test #48:
score: 0
Accepted
time: 872ms
memory: 5880kb
input:
16 1647578253
output:
3589525264
result:
ok good solution
Test #49:
score: 0
Accepted
time: 1402ms
memory: 5880kb
input:
16 1687169193
output:
2777294995
result:
ok good solution
Test #50:
score: 0
Accepted
time: 1914ms
memory: 5880kb
input:
16 702542621
output:
2485649646
result:
ok good solution