結果
| 問題 |
No.8015 アンチローリングハッシュ
|
| ユーザー |
ripity
|
| 提出日時 | 2022-11-21 20:43:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 35 ms / 2,000 ms |
| コード長 | 898 bytes |
| コンパイル時間 | 2,216 ms |
| コンパイル使用メモリ | 206,424 KB |
| 最終ジャッジ日時 | 2025-02-08 23:08:30 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
long long get_hash(string s, long long a, long long b) {
long long hash = 0LL;
for( int i = 0; i < s.length(); i++ ) {
hash = (hash*a+s[i])%b;
}
return hash;
}
int main() {
int N = 4;
long long a, b;
cin >> a >> b;
unordered_map<long long, string> mp;
deque<string> que;
que.emplace_back("");
while( !que.empty() ) {
string crr = que.front();
que.pop_front();
if( crr.length() == N ) {
long long hash = get_hash(crr, a, b);
if( mp.count(hash) ) {
cout << crr << endl;
cout << mp[hash] << endl;
break;
}else {
mp[hash] = crr;
}
}else {
for( char c = 'a'; c <= 'z'; c++ ) {
que.emplace_back(crr+c);
}
}
}
}
ripity