結果

問題 No.3015 アンチローリングハッシュ
ユーザー watchd0gwatchd0g
提出日時 2015-11-12 00:15:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 782 bytes
コンパイル時間 1,192 ms
コンパイル使用メモリ 147,060 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-11 15:40:42
合計ジャッジ時間 3,374 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
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;
}

int main(){
	srand(time(NULL));
	string s,s2;
	int i,j,k,a,b;
	unsigned long long hash,hash2;
	cin >> a >> b;
	for(i=0;i<3;i++){
		s+=rand()%26 + 'a';
	}
	cout << s << endl;
	hash=get_hash(s,a,b);
	s2="aaa";
	for(k=0;k<26;k++){
		s2[0]='a'+k;
		for(i=0;i<26;i++){
			s2[1]='a'+i;
			for(j=0;j<26;j++){
				s2[2]='a'+j;
				hash2=get_hash(s2,a,b);
				if(s!=s2 && hash==hash2){
					cout << s2 << endl;
					break;
				}
			}
			if(s!=s2 && hash==hash2){
				break;
			}
		}
		if(s!=s2 && hash==hash2){
			break;
		}
	}
	return 0;
}
0