QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#19712 | #2492. Hash Function | Wu_Ren | AC ✓ | 1422ms | 3860kb | C++14 | 1.7kb | 2022-02-08 16:53:33 | 2022-05-06 06:47:14 |
Judging History
answer
#include <bits/stdc++.h>
typedef unsigned int ll;
using namespace std;
int n;
ll H,f[32],mod,A0[200],C0[200],A1[200],C1[200];
int s[3][32],s0,s1,s2;
bool v[32];
struct Hash_Table{
const int P=503;
int head[510],o,nxt[200];
ll k[510],c[510];
void clr(){
for(int i=0;i<P;i++) head[i]=0;
o=0;
}
ll& operator [](ll w){
int x=w%P;
for(int i=head[x];i;i=nxt[i]) if(k[i]==w) return c[i];
int p=++o;
return nxt[p]=head[x],head[x]=p,k[p]=w,c[p];
}
bool find(ll w){
int x=w%P;
for(int i=head[x];i;i=nxt[i]) if(k[i]==w) return 1;
return 0;
}
}mp;
inline ll g(ll A,ll C){
return (239ll*A+153ll*C)%mod;
}
int main(){
scanf("%d%u",&n,&H),mod=(1ll<<(2*n-1))-1;
for(int i=0;i<n;i++){
f[i]^=1ll<<i,f[i]^=1ll<<((i-1+2*n)%(2*n));
f[2*i+1]^=1ll<<i,f[2*i+1]^=1ll<<((i-1+2*n)%(2*n));
}
for(int i=n;i<2*n;i++){
f[i]^=1ll<<i,f[i]^=1ll<<((i-1+2*n)%(2*n));
f[4*n-2-2*i]^=1ll<<i,f[4*n-2-2*i]^=1ll<<((i-1+2*n)%(2*n));
}
for(int i=1;i<n-1;i+=2) s[0][s0++]=i,v[i]=1;
for(int i=2*n-2;i>n;i-=2) s[1][s1++]=i,v[i]=1;
for(int i=0;i<2*n;i++) if(!v[i]) s[2][s2++]=i;
for(int S=0;S<(1<<s0);S++) for(int i=0;i<s0;i++) if((S>>i)&1) A0[S]^=1ll<<s[0][i],C0[S]^=f[s[0][i]];
for(int S=0;S<(1<<s1);S++) for(int i=0;i<s1;i++) if((S>>i)&1) A1[S]^=1ll<<s[1][i],C1[S]^=f[s[1][i]];
for(int S2=0;S2<(1<<s2);S2++){
ll A=0,C=0;mp.clr();
for(int i=0;i<s2;i++) if((S2>>i)&1) A^=1ll<<s[2][i],C^=f[s[2][i]];
ll gAC=g(A,C);
for(int S=0;S<(1<<s1);S++) mp[(g(A^A1[S],C^C1[S])-gAC+mod)%mod]=A1[S];
for(int S=0;S<(1<<s0);S++){
ll w=(H-g(A^A0[S],C^C0[S])+mod)%mod;
if(mp.find(w)) printf("%u\n",A^A0[S]^mp[w]),exit(0);
}
}
puts("NTFtxdy");
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 3808kb
input:
4 83
output:
13
result:
ok good solution
Test #2:
score: 0
Accepted
time: 3ms
memory: 3652kb
input:
10 497091
output:
153014
result:
ok good solution
Test #3:
score: 0
Accepted
time: 1ms
memory: 3792kb
input:
4 55
output:
73
result:
ok good solution
Test #4:
score: 0
Accepted
time: 76ms
memory: 3724kb
input:
15 444650548
output:
377677832
result:
ok good solution
Test #5:
score: 0
Accepted
time: 53ms
memory: 3792kb
input:
14 114355996
output:
119238393
result:
ok good solution
Test #6:
score: 0
Accepted
time: 3ms
memory: 3788kb
input:
16 0
output:
0
result:
ok good solution
Test #7:
score: 0
Accepted
time: 3ms
memory: 3772kb
input:
3 22
output:
8
result:
ok good solution
Test #8:
score: 0
Accepted
time: 3ms
memory: 3820kb
input:
8 8319
output:
15407
result:
ok good solution
Test #9:
score: 0
Accepted
time: 13ms
memory: 3776kb
input:
12 7629490
output:
14052612
result:
ok good solution
Test #10:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
2 2
output:
3
result:
ok good solution
Test #11:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
16 0
output:
0
result:
ok good solution
Test #12:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
16 0
output:
0
result:
ok good solution
Test #13:
score: 0
Accepted
time: 2ms
memory: 3860kb
input:
16 0
output:
0
result:
ok good solution
Test #14:
score: 0
Accepted
time: 4ms
memory: 3772kb
input:
11 1086647
output:
1875946
result:
ok good solution
Test #15:
score: 0
Accepted
time: 4ms
memory: 3808kb
input:
11 188671
output:
393405
result:
ok good solution
Test #16:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
11 2028522
output:
424106
result:
ok good solution
Test #17:
score: 0
Accepted
time: 27ms
memory: 3724kb
input:
13 23601796
output:
40518521
result:
ok good solution
Test #18:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
8 29405
output:
7325
result:
ok good solution
Test #19:
score: 0
Accepted
time: 3ms
memory: 3776kb
input:
7 2218
output:
3174
result:
ok good solution
Test #20:
score: 0
Accepted
time: 3ms
memory: 3804kb
input:
7 432
output:
662
result:
ok good solution
Test #21:
score: 0
Accepted
time: 4ms
memory: 3800kb
input:
11 899191
output:
1626482
result:
ok good solution
Test #22:
score: 0
Accepted
time: 3ms
memory: 3816kb
input:
5 494
output:
281
result:
ok good solution
Test #23:
score: 0
Accepted
time: 3ms
memory: 3700kb
input:
8 13862
output:
12212
result:
ok good solution
Test #24:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
11 899027
output:
1622100
result:
ok good solution
Test #25:
score: 0
Accepted
time: 3ms
memory: 3768kb
input:
8 7446
output:
49853
result:
ok good solution
Test #26:
score: 0
Accepted
time: 3ms
memory: 3776kb
input:
3 12
output:
6
result:
ok good solution
Test #27:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
8 6258
output:
18666
result:
ok good solution
Test #28:
score: 0
Accepted
time: 109ms
memory: 3860kb
input:
15 191474555
output:
411455767
result:
ok good solution
Test #29:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
3 17
output:
20
result:
ok good solution
Test #30:
score: 0
Accepted
time: 85ms
memory: 3772kb
input:
15 161474861
output:
318717104
result:
ok good solution
Test #31:
score: 0
Accepted
time: 3ms
memory: 3792kb
input:
10 180816
output:
81147
result:
ok good solution
Test #32:
score: 0
Accepted
time: 3ms
memory: 3724kb
input:
4 116
output:
81
result:
ok good solution
Test #33:
score: 0
Accepted
time: 391ms
memory: 3724kb
input:
16 1196684556
output:
567748713
result:
ok good solution
Test #34:
score: 0
Accepted
time: 280ms
memory: 3792kb
input:
16 1087033358
output:
458416341
result:
ok good solution
Test #35:
score: 0
Accepted
time: 305ms
memory: 3784kb
input:
16 2112546660
output:
1321210677
result:
ok good solution
Test #36:
score: 0
Accepted
time: 910ms
memory: 3792kb
input:
16 130507716
output:
3358127644
result:
ok good solution
Test #37:
score: 0
Accepted
time: 667ms
memory: 3808kb
input:
16 1531459999
output:
1004811660
result:
ok good solution
Test #38:
score: 0
Accepted
time: 76ms
memory: 3796kb
input:
16 1905706077
output:
1437054237
result:
ok good solution
Test #39:
score: 0
Accepted
time: 926ms
memory: 3792kb
input:
16 1584950777
output:
2565491169
result:
ok good solution
Test #40:
score: 0
Accepted
time: 163ms
memory: 3860kb
input:
16 1112585098
output:
312451907
result:
ok good solution
Test #41:
score: 0
Accepted
time: 257ms
memory: 3788kb
input:
16 1527899944
output:
1488817943
result:
ok good solution
Test #42:
score: 0
Accepted
time: 1422ms
memory: 3788kb
input:
16 1234237908
output:
3150139837
result:
ok good solution
Test #43:
score: 0
Accepted
time: 61ms
memory: 3792kb
input:
16 922629865
output:
1149833290
result:
ok good solution
Test #44:
score: 0
Accepted
time: 1229ms
memory: 3856kb
input:
16 2079610945
output:
4169495274
result:
ok good solution
Test #45:
score: 0
Accepted
time: 586ms
memory: 3792kb
input:
16 125431469
output:
2028551108
result:
ok good solution
Test #46:
score: 0
Accepted
time: 667ms
memory: 3792kb
input:
16 425515915
output:
1873120589
result:
ok good solution
Test #47:
score: 0
Accepted
time: 341ms
memory: 3696kb
input:
16 882748949
output:
873576051
result:
ok good solution
Test #48:
score: 0
Accepted
time: 167ms
memory: 3768kb
input:
16 1647578253
output:
45770769
result:
ok good solution
Test #49:
score: 0
Accepted
time: 1028ms
memory: 3808kb
input:
16 1687169193
output:
3025007262
result:
ok good solution
Test #50:
score: 0
Accepted
time: 713ms
memory: 3772kb
input:
16 702542621
output:
2485649646
result:
ok good solution