結果

問題 No.3015 アンチローリングハッシュ
ユーザー cielciel
提出日時 2015-10-31 19:21:46
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,454 bytes
コンパイル時間 983 ms
コンパイル使用メモリ 63,164 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-10-11 07:16:26
合計ジャッジ時間 4,619 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,368 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,368 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <unordered_map>
#include <climits>
#include <cstdio>
#include <unistd.h>
#define lrotl(val,rot) (( (val)<<(rot) )|( (val)>>(sizeof(val)*CHAR_BIT-(rot)) ))

const int N=14;

static unsigned int x = 123456789;
static unsigned int y = 362436069;
static unsigned int z = 521288629;
static unsigned int w = 88675123;

unsigned int xor_rand(){
	unsigned int t;
	t=x^(x<<11);
	x=y;y=z;z=w;
	return w=(w^(w>>19)) ^ (t^(t>>8));
}

// http://d.hatena.ne.jp/gintenlabo/20100930/1285859540
void xor_srand(unsigned int seed){
#if 1
	x^=seed;
	y^=lrotl(seed,17);
	z^=lrotl(seed,31);
	w^=lrotl(seed,18);
#else
	x^=lrotl(seed,14);
	y^=lrotl(seed,31);
	z^=lrotl(seed,13);
	w^=seed;
#endif
}

long long P,B;
long long calc(const std::string &s){
	long long r=0;
	__int128_t b=1;
	int l=s.size();
	for(int i=0;i<s.size();i++){
		r=(r+b*s[l-i-1])%P;
		b=(b*B)%P;
	}
	return r;
}
int main(){
#if 1
	xor_srand((unsigned int)time(NULL)^(getpid()<<16));
	scanf("%lld%lld",&P,&B);
	//P=1000000000000000003;
	//B=123456789987654321;
	std::unordered_map<long long,std::string>h;
	long long cnt=0;
	for(;;cnt++){
		if(cnt%1000000==0)fprintf(stderr,"%lld\n",cnt);
		std::string x;
		for(int i=0;i<N;i++)x+='a'+xor_rand()%26;
		long long v=calc(x);
		if(h.find(v)!=h.end()){
			if(h[v]!=x){
				puts(h[v].c_str());
				puts(x.c_str());
				break;
			}
		}else{
			h[v]=x;
		}
	}
#else
	//328M steps
	puts("wldvxcyhlsptef");
	puts("jnargjrvmnuhzy");
#endif
}
0