結果

問題 No.8015 アンチローリングハッシュ
ユーザー ciel
提出日時 2015-10-31 19:24:32
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,454 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 540 ms
コンパイル使用メモリ 62,236 KB
最終ジャッジ日時 2026-04-04 03:46:54
合計ジャッジ時間 5,990 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:50:33: error: 'time' was not declared in this scope
   50 |         xor_srand((unsigned int)time(NULL)^(getpid()<<16));
      |                                 ^~~~
main.cpp:6:1: note: 'time' is defined in header '<ctime>'; this is probably fixable by adding '#include <ctime>'
    5 | #include <unistd.h>
  +++ |+#include <ctime>
    6 | #define lrotl(val,rot) (( (val)<<(rot) )|( (val)>>(sizeof(val)*CHAR_BIT-(rot)) ))

ソースコード

diff #
raw source code

#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",&B,&P);
	//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