QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#20583 | #2492. Hash Function | _silhouette_ | AC ✓ | 2082ms | 14400kb | C++14 | 2.0kb | 2022-02-16 18:23:14 | 2022-05-03 10:39:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int Max_N=16,Mod=114514;
int n,H,N,M,Num,lin[Mod+5];
long long A[Max_N<<1],B[Max_N<<1],R[Max_N<<1],C[Max_N<<1],a1[1<<19],a2[1<<7],a3[1<<7],c1[1<<19],c2[1<<7],c3[1<<7];
vector<int> S1,S2,S3;
struct Edge{ int Next,val1; long long val2; } e[1<<26];
void Add(int x,long long val){
int h=x%Mod;
for(int i=lin[h];i;i=e[i].Next)
if(e[i].val1==x) return;
e[++Num].Next=lin[h]; lin[h]=Num; e[Num].val1=x; e[Num].val2=val;
}
long long Ask(int x){
int h=x%Mod;
for(int i=lin[h];i;i=e[i].Next)
if(e[i].val1==x) return e[i].val2;
return -1;
}
int main(){
scanf("%d%d",&n,&H);
N=n<<1; M=(1<<(N-1))-1;
for(int i=0;i<N;i++)
if(i<n) B[i]=(1ll<<i)^(1ll<<(2*i+1));
else B[i]=(1ll<<i)^(1ll<<(4*n-2*i-2));
for(int i=0;i<N;i++) R[i]=B[(i+1)%N];
for(int i=0;i<N;i++) C[i]=B[i]^R[i];
for(int i=0;i<N;i++)
for(int j=0;j<N;j++)
if((C[j]>>i)&1) A[i]|=1ll<<j;
for(int i=0;i<N;i++){
int Min=N-1,Max=0;
for(int j=0;j<N;j++)
if((1ll<<j)&A[i])
Min=min(Min,j),
Max=max(Max,j);
if(Max<n) S2.push_back(i);
else if(Min>=n) S3.push_back(i);
else S1.push_back(i);
}
for(int i=0;i<1<<S1.size();i++){
for(int j=0;j<S1.size();j++)
if((1ll<<j)&i) a1[i]^=1ll<<S1[j],c1[i]^=A[S1[j]];
}
for(int i=0;i<1<<S2.size();i++){
for(int j=0;j<S2.size();j++)
if((1ll<<j)&i) a2[i]^=1ll<<S2[j],c2[i]^=A[S2[j]];
}
for(int i=0;i<1<<S3.size();i++){
for(int j=0;j<S3.size();j++)
if((1ll<<j)&i) a3[i]^=1ll<<S3[j],c3[i]^=A[S3[j]];
}
int s=(1ll<<N)-(1ll<<n);
for(int i=0;i<1<<S1.size();i++){
for(int j=0;j<1<<S2.size();j++){
int val=(239ll*a2[j]+153ll*((c1[i]^c2[j])&((1ll<<n)-1)))%M;
Add(val,a2[j]);
}
for(int j=0;j<1<<S3.size();j++){
int val=(H-(239ll*(a1[i]+a3[j])+153ll*((c1[i]^c3[j])&((1ll<<N)-(1ll<<n))))%M+M)%M;
unsigned int ans=Ask(val);
if(ans!=-1){ printf("%u\n",ans^a1[i]^a3[j]); return 0; }
}
Num=0;
for(int j=0;j<1<<S2.size();j++)
lin[(239ll*a2[j]+153ll*((c1[i]^c2[j])&((1ll<<n)-1)))%M%Mod]=0;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 3812kb
input:
4 83
output:
13
result:
ok good solution
Test #2:
score: 0
Accepted
time: 4ms
memory: 4444kb
input:
10 497091
output:
153014
result:
ok good solution
Test #3:
score: 0
Accepted
time: 3ms
memory: 5828kb
input:
4 55
output:
73
result:
ok good solution
Test #4:
score: 0
Accepted
time: 307ms
memory: 9680kb
input:
15 444650548
output:
377677832
result:
ok good solution
Test #5:
score: 0
Accepted
time: 175ms
memory: 8184kb
input:
14 114355996
output:
119238393
result:
ok good solution
Test #6:
score: 0
Accepted
time: 38ms
memory: 13312kb
input:
16 0
output:
0
result:
ok good solution
Test #7:
score: 0
Accepted
time: 1ms
memory: 5836kb
input:
3 22
output:
8
result:
ok good solution
Test #8:
score: 0
Accepted
time: 4ms
memory: 5976kb
input:
8 8319
output:
15407
result:
ok good solution
Test #9:
score: 0
Accepted
time: 21ms
memory: 6616kb
input:
12 7629490
output:
11766463
result:
ok good solution
Test #10:
score: 0
Accepted
time: 1ms
memory: 5912kb
input:
2 2
output:
3
result:
ok good solution
Test #11:
score: 0
Accepted
time: 35ms
memory: 14052kb
input:
16 0
output:
0
result:
ok good solution
Test #12:
score: 0
Accepted
time: 30ms
memory: 12680kb
input:
16 0
output:
0
result:
ok good solution
Test #13:
score: 0
Accepted
time: 21ms
memory: 13980kb
input:
16 0
output:
0
result:
ok good solution
Test #14:
score: 0
Accepted
time: 7ms
memory: 6424kb
input:
11 1086647
output:
1875946
result:
ok good solution
Test #15:
score: 0
Accepted
time: 5ms
memory: 6404kb
input:
11 188671
output:
393405
result:
ok good solution
Test #16:
score: 0
Accepted
time: 3ms
memory: 6396kb
input:
11 2028522
output:
424106
result:
ok good solution
Test #17:
score: 0
Accepted
time: 58ms
memory: 6872kb
input:
13 23601796
output:
40518521
result:
ok good solution
Test #18:
score: 0
Accepted
time: 3ms
memory: 6060kb
input:
8 29405
output:
7325
result:
ok good solution
Test #19:
score: 0
Accepted
time: 0ms
memory: 5888kb
input:
7 2218
output:
3174
result:
ok good solution
Test #20:
score: 0
Accepted
time: 1ms
memory: 5824kb
input:
7 432
output:
662
result:
ok good solution
Test #21:
score: 0
Accepted
time: 3ms
memory: 6416kb
input:
11 899191
output:
570326
result:
ok good solution
Test #22:
score: 0
Accepted
time: 3ms
memory: 5912kb
input:
5 494
output:
281
result:
ok good solution
Test #23:
score: 0
Accepted
time: 4ms
memory: 5972kb
input:
8 13862
output:
12212
result:
ok good solution
Test #24:
score: 0
Accepted
time: 11ms
memory: 6420kb
input:
11 899027
output:
1622100
result:
ok good solution
Test #25:
score: 0
Accepted
time: 4ms
memory: 5920kb
input:
8 7446
output:
49853
result:
ok good solution
Test #26:
score: 0
Accepted
time: 3ms
memory: 5824kb
input:
3 12
output:
6
result:
ok good solution
Test #27:
score: 0
Accepted
time: 4ms
memory: 5920kb
input:
8 6258
output:
18666
result:
ok good solution
Test #28:
score: 0
Accepted
time: 309ms
memory: 8732kb
input:
15 191474555
output:
411455767
result:
ok good solution
Test #29:
score: 0
Accepted
time: 1ms
memory: 5840kb
input:
3 17
output:
20
result:
ok good solution
Test #30:
score: 0
Accepted
time: 291ms
memory: 9408kb
input:
15 161474861
output:
318717104
result:
ok good solution
Test #31:
score: 0
Accepted
time: 4ms
memory: 6352kb
input:
10 180816
output:
81147
result:
ok good solution
Test #32:
score: 0
Accepted
time: 4ms
memory: 5796kb
input:
4 116
output:
81
result:
ok good solution
Test #33:
score: 0
Accepted
time: 343ms
memory: 12488kb
input:
16 1196684556
output:
567748713
result:
ok good solution
Test #34:
score: 0
Accepted
time: 235ms
memory: 13992kb
input:
16 1087033358
output:
458416341
result:
ok good solution
Test #35:
score: 0
Accepted
time: 809ms
memory: 12844kb
input:
16 2112546660
output:
1321210677
result:
ok good solution
Test #36:
score: 0
Accepted
time: 1808ms
memory: 13140kb
input:
16 130507716
output:
3358127644
result:
ok good solution
Test #37:
score: 0
Accepted
time: 552ms
memory: 12568kb
input:
16 1531459999
output:
1004811660
result:
ok good solution
Test #38:
score: 0
Accepted
time: 627ms
memory: 14400kb
input:
16 1905706077
output:
1437054237
result:
ok good solution
Test #39:
score: 0
Accepted
time: 1313ms
memory: 13472kb
input:
16 1584950777
output:
2565491169
result:
ok good solution
Test #40:
score: 0
Accepted
time: 149ms
memory: 13284kb
input:
16 1112585098
output:
312451907
result:
ok good solution
Test #41:
score: 0
Accepted
time: 768ms
memory: 13640kb
input:
16 1527899944
output:
1488817943
result:
ok good solution
Test #42:
score: 0
Accepted
time: 1646ms
memory: 14008kb
input:
16 1234237908
output:
3150139837
result:
ok good solution
Test #43:
score: 0
Accepted
time: 260ms
memory: 13004kb
input:
16 922629865
output:
237178966
result:
ok good solution
Test #44:
score: 0
Accepted
time: 2082ms
memory: 13728kb
input:
16 2079610945
output:
4169495274
result:
ok good solution
Test #45:
score: 0
Accepted
time: 1052ms
memory: 12916kb
input:
16 125431469
output:
2028551108
result:
ok good solution
Test #46:
score: 0
Accepted
time: 1100ms
memory: 13588kb
input:
16 425515915
output:
1873120589
result:
ok good solution
Test #47:
score: 0
Accepted
time: 303ms
memory: 14360kb
input:
16 882748949
output:
873576051
result:
ok good solution
Test #48:
score: 0
Accepted
time: 166ms
memory: 12960kb
input:
16 1647578253
output:
45770769
result:
ok good solution
Test #49:
score: 0
Accepted
time: 1399ms
memory: 13284kb
input:
16 1687169193
output:
3025007262
result:
ok good solution
Test #50:
score: 0
Accepted
time: 1134ms
memory: 13740kb
input:
16 702542621
output:
2485649646
result:
ok good solution