結果

問題 No.3015 アンチローリングハッシュ
ユーザー furafura
提出日時 2020-05-06 17:20:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 590 bytes
コンパイル時間 2,282 ms
コンパイル使用メモリ 203,340 KB
実行使用メモリ 6,076 KB
最終ジャッジ日時 2023-09-11 04:45:43
合計ジャッジ時間 3,970 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

unsigned long long get_hash(string s, unsigned long long a, unsigned long long b){
	unsigned long long hash = 0;

	for(int i = 0; i < s.size(); i++){
		hash = (hash * a + s[i]) % b;
	}

	return hash;
}

random_device seed_gen;
mt19937 rng(seed_gen());

int main(){
	int a,b; cin>>a>>b;

	vector<string> H(b);
	while(1){
		string s;
		rep(i,30) s+='a'+rng()%26;
		int h=get_hash(s,a,b);
		if(H[h].empty()){
			H[h]=s;
		}
		else if(H[h]!=s){
			cout<<H[h]<<'\n'<<s<<'\n';
			break;
		}
	}
	return 0;
}
0