結果

問題 No.3015 アンチローリングハッシュ
ユーザー koyumeishikoyumeishi
提出日時 2015-06-29 01:35:22
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 743 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 61,908 KB
実行使用メモリ 8,768 KB
最終ジャッジ日時 2023-09-22 04:21:28
合計ジャッジ時間 5,013 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include "assert.h"
#include <fstream>
#include <vector>
#include <ctime>
#include <cstdlib>

using namespace std;

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

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

	return hash;
}

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

	srand((unsigned)time(NULL));

	string s(2*b, 'a');
	for(int i=0; i<s.size(); i++){
		s[i] = 'a' + rand()%26;
	}
	unsigned long long hash_s = get_hash(s,a,b);

	string t(2*b, 'a');
	while(1){
		while(get_hash(t,a,b) != hash_s){
			for(int k=0; k<3; k++){
				t[rand()%t.size()] = 'a' + rand()%26;
			}
		}
		if(s != t) break;
	}

	cout << s << endl;
	cout << t << endl;
	return 0;
}
0