結果

問題 No.8015 アンチローリングハッシュ
ユーザー watchd0g
提出日時 2015-11-12 00:01:46
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 690 bytes
コンパイル時間 1,236 ms
コンパイル使用メモリ 162,032 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-13 14:27:17
合計ジャッジ時間 4,252 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 3 WA * 18
権限があれば一括ダウンロードができます

ソースコード

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,a,b;
	unsigned long long hash,hash2;
	cin >> a >> b;
	for(i=0;i<2;i++){
		s+=rand()%26 + 'a';
	}
	cout << s << endl;
	hash=get_hash(s,a,b);
	s2="aa";
	for(i=0;i<26;i++){
		for(j=0;j<26;j++){
			s2[0]=s2[0]+i;
			s2[1]=s2[1]+j;
			hash2=get_hash(s2,a,b);
			if(s!=s2 && hash==hash2){
				cout << s2 << endl;
				break;
			}
		}
		if(s!=s2 && hash==hash2){
			break;
		}
	}
	return 0;
}
0