QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#20894 | #2492. Hash Function | uezexh | TL | 2491ms | 3308kb | C++17 | 2.0kb | 2022-02-20 21:29:08 | 2022-05-03 11:51:24 |
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=(1u<<S[0].size());~S0;--S0){
unsigned A0=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){
unsigned A=0,C=C_;
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);
}
sort(h.begin(),h.end());
for(unsigned S2=0;S2<(1u<<S[2].size());++S2){
unsigned A=0,C=C_;
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;
}
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3152kb
input:
4 83
output:
145
result:
ok good solution
Test #2:
score: 0
Accepted
time: 2ms
memory: 3120kb
input:
10 497091
output:
548470
result:
ok good solution
Test #3:
score: 0
Accepted
time: 0ms
memory: 3148kb
input:
4 55
output:
234
result:
ok good solution
Test #4:
score: 0
Accepted
time: 613ms
memory: 3156kb
input:
15 444650548
output:
531938370
result:
ok good solution
Test #5:
score: 0
Accepted
time: 194ms
memory: 3172kb
input:
14 114355996
output:
125553692
result:
ok good solution
Test #6:
score: 0
Accepted
time: 2ms
memory: 3196kb
input:
16 0
output:
0
result:
ok good solution
Test #7:
score: 0
Accepted
time: 2ms
memory: 3140kb
input:
3 22
output:
63
result:
ok good solution
Test #8:
score: 0
Accepted
time: 1ms
memory: 3196kb
input:
8 8319
output:
47842
result:
ok good solution
Test #9:
score: 0
Accepted
time: 6ms
memory: 3168kb
input:
12 7629490
output:
15121216
result:
ok good solution
Test #10:
score: 0
Accepted
time: 0ms
memory: 3180kb
input:
2 2
output:
3
result:
ok good solution
Test #11:
score: 0
Accepted
time: 3ms
memory: 3116kb
input:
16 0
output:
0
result:
ok good solution
Test #12:
score: 0
Accepted
time: 2ms
memory: 3156kb
input:
16 0
output:
0
result:
ok good solution
Test #13:
score: 0
Accepted
time: 2ms
memory: 3196kb
input:
16 0
output:
0
result:
ok good solution
Test #14:
score: 0
Accepted
time: 6ms
memory: 3116kb
input:
11 1086647
output:
1875946
result:
ok good solution
Test #15:
score: 0
Accepted
time: 4ms
memory: 3184kb
input:
11 188671
output:
3617165
result:
ok good solution
Test #16:
score: 0
Accepted
time: 2ms
memory: 3152kb
input:
11 2028522
output:
3482225
result:
ok good solution
Test #17:
score: 0
Accepted
time: 54ms
memory: 3144kb
input:
13 23601796
output:
40518521
result:
ok good solution
Test #18:
score: 0
Accepted
time: 3ms
memory: 3236kb
input:
8 29405
output:
39139
result:
ok good solution
Test #19:
score: 0
Accepted
time: 0ms
memory: 3220kb
input:
7 2218
output:
13098
result:
ok good solution
Test #20:
score: 0
Accepted
time: 2ms
memory: 3196kb
input:
7 432
output:
13621
result:
ok good solution
Test #21:
score: 0
Accepted
time: 3ms
memory: 3116kb
input:
11 899191
output:
4131409
result:
ok good solution
Test #22:
score: 0
Accepted
time: 3ms
memory: 3176kb
input:
5 494
output:
281
result:
ok good solution
Test #23:
score: 0
Accepted
time: 1ms
memory: 3308kb
input:
8 13862
output:
51543
result:
ok good solution
Test #24:
score: 0
Accepted
time: 2ms
memory: 3144kb
input:
11 899027
output:
3346232
result:
ok good solution
Test #25:
score: 0
Accepted
time: 3ms
memory: 3164kb
input:
8 7446
output:
49853
result:
ok good solution
Test #26:
score: 0
Accepted
time: 2ms
memory: 3160kb
input:
3 12
output:
54
result:
ok good solution
Test #27:
score: 0
Accepted
time: 3ms
memory: 3308kb
input:
8 6258
output:
18666
result:
ok good solution
Test #28:
score: 0
Accepted
time: 740ms
memory: 3180kb
input:
15 191474555
output:
411455767
result:
ok good solution
Test #29:
score: 0
Accepted
time: 0ms
memory: 3140kb
input:
3 17
output:
28
result:
ok good solution
Test #30:
score: 0
Accepted
time: 684ms
memory: 3184kb
input:
15 161474861
output:
520423443
result:
ok good solution
Test #31:
score: 0
Accepted
time: 1ms
memory: 3164kb
input:
10 180816
output:
869271
result:
ok good solution
Test #32:
score: 0
Accepted
time: 2ms
memory: 3236kb
input:
4 116
output:
246
result:
ok good solution
Test #33:
score: 0
Accepted
time: 2491ms
memory: 3124kb
input:
16 1196684556
output:
1973553583
result:
ok good solution
Test #34:
score: 0
Accepted
time: 548ms
memory: 3164kb
input:
16 1087033358
output:
3403352030
result:
ok good solution
Test #35:
score: 0
Accepted
time: 1130ms
memory: 3168kb
input:
16 2112546660
output:
2823255398
result:
ok good solution
Test #36:
score: 0
Accepted
time: 645ms
memory: 3196kb
input:
16 130507716
output:
3358127644
result:
ok good solution
Test #37:
score: -100
Time Limit Exceeded
input:
16 1531459999