結果

問題 No.3015 アンチローリングハッシュ
ユーザー ripityripity
提出日時 2022-11-21 20:43:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 898 bytes
コンパイル時間 5,776 ms
コンパイル使用メモリ 215,400 KB
実行使用メモリ 19,464 KB
最終ジャッジ日時 2023-10-23 17:22:58
合計ジャッジ時間 5,070 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
18,368 KB
testcase_01 AC 26 ms
18,368 KB
testcase_02 AC 26 ms
18,368 KB
testcase_03 AC 26 ms
18,368 KB
testcase_04 AC 27 ms
18,368 KB
testcase_05 AC 25 ms
18,368 KB
testcase_06 AC 26 ms
18,368 KB
testcase_07 AC 27 ms
18,368 KB
testcase_08 AC 26 ms
18,388 KB
testcase_09 AC 28 ms
18,408 KB
testcase_10 AC 34 ms
19,464 KB
testcase_11 AC 33 ms
19,464 KB
testcase_12 AC 29 ms
18,556 KB
testcase_13 AC 31 ms
18,936 KB
testcase_14 AC 27 ms
18,524 KB
testcase_15 AC 26 ms
18,388 KB
testcase_16 AC 33 ms
19,464 KB
testcase_17 AC 31 ms
19,084 KB
testcase_18 AC 27 ms
18,368 KB
testcase_19 AC 26 ms
18,368 KB
testcase_20 AC 26 ms
18,368 KB
testcase_21 AC 26 ms
18,368 KB
testcase_22 AC 27 ms
18,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
            }
        }
    }
}
0