QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#20892 | #2492. Hash Function | uezexh | TL | 1998ms | 3236kb | C++17 | 2.2kb | 2022-02-20 20:51:22 | 2022-05-03 11:51:03 |
Judging History
answer
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<typename T> void cmin(T &a,const T &b){if(b<a)a=b;}
template<typename T> void cmax(T &a,const T &b){if(a<b)a=b;}
int n;
unsigned H;
vector<int> s[32],S[3];
vector<unsigned> b,c;
unsigned sub(unsigned a,unsigned b){return a<b?a+((1u<<(n*2-1))-1)-b:a-b;}
int main(){
scanf("%d%u",&n,&H);
b.resize(n*2),c.resize(n*2);
for(int i=0;i<n;++i)
b[i]=(1u<<i)^(1u<<(i*2+1));
for(int i=n;i<n*2;++i)
b[i]=(1u<<i)^(1u<<(n*4-i*2-2));
for(int i=0;i<n*2;++i)
c[i]=b[i]^b[(i+1)%(n*2)];
for(int i=0;i<n*2;++i)
for(int j=0;j<n*2;++j)
if((c[i]>>j)&1)
s[j].push_back(i);
for(int i=0;i<n*2;++i){
if(!s[i].size())
continue;
if(*max_element(s[i].begin(),s[i].end())<n){
S[1].push_back(i);
}else if(*min_element(s[i].begin(),s[i].end())>=n){
S[2].push_back(i);
}else{
S[0].push_back(i);
}
}
for(unsigned S0=0;S0<(1u<<S[0].size());++S0){
unsigned A0=0,A=0,C=0;
for(int i=0;i<int(S[0].size());++i)
if((S0>>i)&1){
A0^=(1u<<S[0][i]);
for(int j:s[S[0][i]])
C^=(1u<<j);
}
vector<pair<unsigned,unsigned>> h;
for(unsigned S1=0;S1<(1u<<S[1].size());++S1){
for(int i=0;i<int(S[1].size());++i)
if((S1>>i)&1){
A^=(1u<<S[1][i]);
for(int j:s[S[1][i]])
C^=(1u<<j);
}
h.emplace_back((A*239LLu+(C&((1u<<n)-1))*153LLu)%(((1u<<(n*2-1))-1)),A);
for(int i=0;i<int(S[1].size());++i)
if((S1>>i)&1){
A^=(1u<<S[1][i]);
for(int j:s[S[1][i]])
C^=(1u<<j);
}
}
sort(h.begin(),h.end());
for(unsigned S2=0;S2<(1u<<S[2].size());++S2){
for(int i=0;i<int(S[2].size());++i)
if((S2>>i)&1){
A^=(1u<<S[2][i]);
for(int j:s[S[2][i]])
C^=(1u<<j);
}
unsigned t=sub(H,((A0+A)*239LLu+(C&~((1u<<n)-1))*153LLu)%((1u<<(n*2-1))-1));
auto it=lower_bound(h.begin(),h.end(),pair{t,0u});
if(it!=h.end() && it->first==t){
A^=A0^it->second;
printf("%u\n",A);
return 0;
}
for(int i=0;i<int(S[2].size());++i)
if((S2>>i)&1){
A^=(1u<<S[2][i]);
for(int j:s[S[2][i]])
C^=(1u<<j);
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3152kb
input:
4 83
output:
13
result:
ok good solution
Test #2:
score: 0
Accepted
time: 1ms
memory: 3172kb
input:
10 497091
output:
153014
result:
ok good solution
Test #3:
score: 0
Accepted
time: 2ms
memory: 3224kb
input:
4 55
output:
73
result:
ok good solution
Test #4:
score: 0
Accepted
time: 567ms
memory: 3184kb
input:
15 444650548
output:
377677832
result:
ok good solution
Test #5:
score: 0
Accepted
time: 206ms
memory: 3172kb
input:
14 114355996
output:
119238393
result:
ok good solution
Test #6:
score: 0
Accepted
time: 0ms
memory: 3196kb
input:
16 0
output:
0
result:
ok good solution
Test #7:
score: 0
Accepted
time: 1ms
memory: 3188kb
input:
3 22
output:
8
result:
ok good solution
Test #8:
score: 0
Accepted
time: 0ms
memory: 3196kb
input:
8 8319
output:
47842
result:
ok good solution
Test #9:
score: 0
Accepted
time: 47ms
memory: 3196kb
input:
12 7629490
output:
11766463
result:
ok good solution
Test #10:
score: 0
Accepted
time: 2ms
memory: 3112kb
input:
2 2
output:
3
result:
ok good solution
Test #11:
score: 0
Accepted
time: 2ms
memory: 3144kb
input:
16 0
output:
0
result:
ok good solution
Test #12:
score: 0
Accepted
time: 2ms
memory: 3140kb
input:
16 0
output:
0
result:
ok good solution
Test #13:
score: 0
Accepted
time: 2ms
memory: 3156kb
input:
16 0
output:
0
result:
ok good solution
Test #14:
score: 0
Accepted
time: 7ms
memory: 3140kb
input:
11 1086647
output:
1875946
result:
ok good solution
Test #15:
score: 0
Accepted
time: 2ms
memory: 3152kb
input:
11 188671
output:
393405
result:
ok good solution
Test #16:
score: 0
Accepted
time: 14ms
memory: 3152kb
input:
11 2028522
output:
3482225
result:
ok good solution
Test #17:
score: 0
Accepted
time: 107ms
memory: 3236kb
input:
13 23601796
output:
40518521
result:
ok good solution
Test #18:
score: 0
Accepted
time: 2ms
memory: 3188kb
input:
8 29405
output:
39139
result:
ok good solution
Test #19:
score: 0
Accepted
time: 3ms
memory: 3156kb
input:
7 2218
output:
3174
result:
ok good solution
Test #20:
score: 0
Accepted
time: 2ms
memory: 3184kb
input:
7 432
output:
662
result:
ok good solution
Test #21:
score: 0
Accepted
time: 2ms
memory: 3156kb
input:
11 899191
output:
570326
result:
ok good solution
Test #22:
score: 0
Accepted
time: 0ms
memory: 3180kb
input:
5 494
output:
281
result:
ok good solution
Test #23:
score: 0
Accepted
time: 4ms
memory: 3168kb
input:
8 13862
output:
51543
result:
ok good solution
Test #24:
score: 0
Accepted
time: 15ms
memory: 3152kb
input:
11 899027
output:
3346232
result:
ok good solution
Test #25:
score: 0
Accepted
time: 3ms
memory: 3196kb
input:
8 7446
output:
49853
result:
ok good solution
Test #26:
score: 0
Accepted
time: 2ms
memory: 3180kb
input:
3 12
output:
6
result:
ok good solution
Test #27:
score: 0
Accepted
time: 3ms
memory: 3192kb
input:
8 6258
output:
18666
result:
ok good solution
Test #28:
score: 0
Accepted
time: 708ms
memory: 3188kb
input:
15 191474555
output:
411455767
result:
ok good solution
Test #29:
score: 0
Accepted
time: 0ms
memory: 3188kb
input:
3 17
output:
20
result:
ok good solution
Test #30:
score: 0
Accepted
time: 619ms
memory: 3200kb
input:
15 161474861
output:
318717104
result:
ok good solution
Test #31:
score: 0
Accepted
time: 3ms
memory: 3196kb
input:
10 180816
output:
81147
result:
ok good solution
Test #32:
score: 0
Accepted
time: 0ms
memory: 3188kb
input:
4 116
output:
81
result:
ok good solution
Test #33:
score: 0
Accepted
time: 926ms
memory: 3232kb
input:
16 1196684556
output:
567748713
result:
ok good solution
Test #34:
score: 0
Accepted
time: 620ms
memory: 3156kb
input:
16 1087033358
output:
458416341
result:
ok good solution
Test #35:
score: 0
Accepted
time: 1998ms
memory: 3176kb
input:
16 2112546660
output:
1321210677
result:
ok good solution
Test #36:
score: -100
Time Limit Exceeded
input:
16 130507716