QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#20891#2492. Hash FunctionuezexhTL 1685ms3376kbC++172.3kb2022-02-20 20:37:372022-05-03 11:50:51

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:50:51]
  • 评测
  • 测评结果:TL
  • 用时:1685ms
  • 内存:3376kb
  • [2022-02-20 20:37:37]
  • 提交

answer

#include <cstdio>
#include <map>
#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;

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 A=0;A<(1u<<(n*2));++A){
	// 	unsigned C=0;
	// 	for(int i=0;i<n*2;++i)
	// 		if((A>>i)&1)
	// 			for(int j:s[i])
	// 				C^=(1u<<j);
	// 	if(((239u*A+153u*C)%((1u<<(n*2-1))-1))==H)
	// 		printf("%u\n",A);
	// }
	// return 0;
	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);
			}
		map<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[(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);
				}
		}
		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);
				}
			auto it=h.find((H+((1u<<(n*2-1))-1)-(((A0+A)*239LLu+(C&~((1u<<n)-1))*153LLu)%((1u<<(n*2-1))-1)))%((1u<<(n*2-1))-1));
			if(it!=h.end()){
				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: 3ms
memory: 3244kb

input:

4 83

output:

13

result:

ok good solution

Test #2:

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

input:

10 497091

output:

153014

result:

ok good solution

Test #3:

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

input:

4 55

output:

73

result:

ok good solution

Test #4:

score: 0
Accepted
time: 974ms
memory: 3288kb

input:

15 444650548

output:

377677832

result:

ok good solution

Test #5:

score: 0
Accepted
time: 394ms
memory: 3376kb

input:

14 114355996

output:

119238393

result:

ok good solution

Test #6:

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

input:

16 0

output:

0

result:

ok good solution

Test #7:

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

input:

3 22

output:

8

result:

ok good solution

Test #8:

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

input:

8 8319

output:

47842

result:

ok good solution

Test #9:

score: 0
Accepted
time: 77ms
memory: 3256kb

input:

12 7629490

output:

11766463

result:

ok good solution

Test #10:

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

input:

2 2

output:

3

result:

ok good solution

Test #11:

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

input:

16 0

output:

0

result:

ok good solution

Test #12:

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

input:

16 0

output:

0

result:

ok good solution

Test #13:

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

input:

16 0

output:

0

result:

ok good solution

Test #14:

score: 0
Accepted
time: 12ms
memory: 3296kb

input:

11 1086647

output:

1875946

result:

ok good solution

Test #15:

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

input:

11 188671

output:

393405

result:

ok good solution

Test #16:

score: 0
Accepted
time: 21ms
memory: 3228kb

input:

11 2028522

output:

3482225

result:

ok good solution

Test #17:

score: 0
Accepted
time: 176ms
memory: 3260kb

input:

13 23601796

output:

40518521

result:

ok good solution

Test #18:

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

input:

8 29405

output:

39139

result:

ok good solution

Test #19:

score: 0
Accepted
time: 0ms
memory: 3236kb

input:

7 2218

output:

3174

result:

ok good solution

Test #20:

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

input:

7 432

output:

662

result:

ok good solution

Test #21:

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

input:

11 899191

output:

570326

result:

ok good solution

Test #22:

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

input:

5 494

output:

281

result:

ok good solution

Test #23:

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

input:

8 13862

output:

51543

result:

ok good solution

Test #24:

score: 0
Accepted
time: 21ms
memory: 3184kb

input:

11 899027

output:

3346232

result:

ok good solution

Test #25:

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

input:

8 7446

output:

49853

result:

ok good solution

Test #26:

score: 0
Accepted
time: 0ms
memory: 3300kb

input:

3 12

output:

6

result:

ok good solution

Test #27:

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

input:

8 6258

output:

18666

result:

ok good solution

Test #28:

score: 0
Accepted
time: 1143ms
memory: 3180kb

input:

15 191474555

output:

411455767

result:

ok good solution

Test #29:

score: 0
Accepted
time: 0ms
memory: 3192kb

input:

3 17

output:

20

result:

ok good solution

Test #30:

score: 0
Accepted
time: 1029ms
memory: 3296kb

input:

15 161474861

output:

318717104

result:

ok good solution

Test #31:

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

input:

10 180816

output:

81147

result:

ok good solution

Test #32:

score: 0
Accepted
time: 0ms
memory: 3300kb

input:

4 116

output:

81

result:

ok good solution

Test #33:

score: 0
Accepted
time: 1685ms
memory: 3248kb

input:

16 1196684556

output:

567748713

result:

ok good solution

Test #34:

score: 0
Accepted
time: 1119ms
memory: 3248kb

input:

16 1087033358

output:

458416341

result:

ok good solution

Test #35:

score: -100
Time Limit Exceeded

input:

16 2112546660

output:


result: