QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#20885#2492. Hash FunctionhouzhiyuanakioiWA 2718ms5936kbC++1.9kb2022-02-20 17:08:122022-05-03 11:49:37

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-03 11:49:37]
  • 评测
  • 测评结果:WA
  • 用时:2718ms
  • 内存:5936kb
  • [2022-02-20 17:08:12]
  • 提交

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(int 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: 1ms
memory: 5784kb

input:

4 83

output:

145

result:

ok good solution

Test #2:

score: 0
Accepted
time: 6ms
memory: 5936kb

input:

10 497091

output:

548470

result:

ok good solution

Test #3:

score: 0
Accepted
time: 1ms
memory: 5880kb

input:

4 55

output:

234

result:

ok good solution

Test #4:

score: 0
Accepted
time: 750ms
memory: 5740kb

input:

15 444650548

output:

531938370

result:

ok good solution

Test #5:

score: 0
Accepted
time: 276ms
memory: 5884kb

input:

14 114355996

output:

125553692

result:

ok good solution

Test #6:

score: 0
Accepted
time: 2715ms
memory: 5740kb

input:

16 0

output:

1401112553

result:

ok good solution

Test #7:

score: 0
Accepted
time: 3ms
memory: 5876kb

input:

3 22

output:

63

result:

ok good solution

Test #8:

score: 0
Accepted
time: 3ms
memory: 5724kb

input:

8 8319

output:

62746

result:

ok good solution

Test #9:

score: 0
Accepted
time: 3ms
memory: 5880kb

input:

12 7629490

output:

15121216

result:

ok good solution

Test #10:

score: 0
Accepted
time: 2ms
memory: 5792kb

input:

2 2

output:

14

result:

ok good solution

Test #11:

score: 0
Accepted
time: 2711ms
memory: 5844kb

input:

16 0

output:

1401112553

result:

ok good solution

Test #12:

score: 0
Accepted
time: 2718ms
memory: 5880kb

input:

16 0

output:

1401112553

result:

ok good solution

Test #13:

score: 0
Accepted
time: 2715ms
memory: 5796kb

input:

16 0

output:

1401112553

result:

ok good solution

Test #14:

score: 0
Accepted
time: 6ms
memory: 5788kb

input:

11 1086647

output:

3757717

result:

ok good solution

Test #15:

score: 0
Accepted
time: 3ms
memory: 5792kb

input:

11 188671

output:

3617165

result:

ok good solution

Test #16:

score: 0
Accepted
time: 8ms
memory: 5884kb

input:

11 2028522

output:

3482225

result:

ok good solution

Test #17:

score: 0
Accepted
time: 76ms
memory: 5792kb

input:

13 23601796

output:

40518521

result:

ok good solution

Test #18:

score: 0
Accepted
time: 3ms
memory: 5784kb

input:

8 29405

output:

42924

result:

ok good solution

Test #19:

score: 0
Accepted
time: 1ms
memory: 5872kb

input:

7 2218

output:

13098

result:

ok good solution

Test #20:

score: 0
Accepted
time: 2ms
memory: 5840kb

input:

7 432

output:

13621

result:

ok good solution

Test #21:

score: 0
Accepted
time: 4ms
memory: 5788kb

input:

11 899191

output:

4131409

result:

ok good solution

Test #22:

score: 0
Accepted
time: 3ms
memory: 5828kb

input:

5 494

output:

281

result:

ok good solution

Test #23:

score: 0
Accepted
time: 4ms
memory: 5732kb

input:

8 13862

output:

51543

result:

ok good solution

Test #24:

score: 0
Accepted
time: 3ms
memory: 5884kb

input:

11 899027

output:

3346232

result:

ok good solution

Test #25:

score: 0
Accepted
time: 3ms
memory: 5860kb

input:

8 7446

output:

53245

result:

ok good solution

Test #26:

score: 0
Accepted
time: 3ms
memory: 5784kb

input:

3 12

output:

54

result:

ok good solution

Test #27:

score: 0
Accepted
time: 2ms
memory: 5824kb

input:

8 6258

output:

58462

result:

ok good solution

Test #28:

score: 0
Accepted
time: 851ms
memory: 5880kb

input:

15 191474555

output:

411455767

result:

ok good solution

Test #29:

score: 0
Accepted
time: 3ms
memory: 5732kb

input:

3 17

output:

28

result:

ok good solution

Test #30:

score: 0
Accepted
time: 809ms
memory: 5832kb

input:

15 161474861

output:

520423443

result:

ok good solution

Test #31:

score: 0
Accepted
time: 2ms
memory: 5752kb

input:

10 180816

output:

869271

result:

ok good solution

Test #32:

score: 0
Accepted
time: 1ms
memory: 5860kb

input:

4 116

output:

246

result:

ok good solution

Test #33:

score: -100
Wrong Answer
time: 303ms
memory: 5796kb

input:

16 1196684556

output:

-154892738

result:

wrong answer Integer -154892738 violates the range [0, 4294967295]