結果

問題 No.3015 アンチローリングハッシュ
ユーザー i_am_nicolen_22i_am_nicolen_22
提出日時 2019-08-16 01:37:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,250 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 164,092 KB
実行使用メモリ 4,452 KB
最終ジャッジ日時 2023-10-19 19:44:08
合計ジャッジ時間 2,789 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

using ull = unsigned long long;
vector<ll>rolling_hash_search(string s,string t){
    vector<long long >index_list;
    ll SL=s.size();
    ll TL=t.size();

    ull b=1e8+7;
    ull a=1;
    for (int i = 0; i < TL; i++)
    {
        a*=b;
    }
    ull s_hash = 0;
    for (int i = 0; i < TL; i++)
    {
        s_hash=s_hash*b+s[i];
    }
    ull t_hash=0;
    for (int i = 0; i < TL; i++)
    {
        t_hash=t_hash*b+t[i];
    }
    for (int i = 0; i < SL-TL+1; i++)
    {
        if(s_hash==t_hash) index_list.push_back(i);
        if(i+TL<SL) s_hash=s_hash*b-s[i]*a+s[i+TL];
    }
    return index_list;
}

int main(){
    int a,b;
    cin>>a>>b;
    a%=b;
    vector<ll>v(b,-1);
    ll idx=1;
    ll endidx;
    ll swidx;
    ll copy=a;
    v[a]=0;
    while(1){
        copy*=a;
        copy%=b;
        if(v[copy]>=0){
            endidx=idx;
            swidx=v[copy];
            break;
        }
        else{
            v[copy]=idx;
        }
        idx++;
    }
    string s,t;
    for (int i = 0; i <=endidx+1; i++)
    {
        s.push_back('a');
        t.push_back('a');
    }
    s[endidx-swidx]='b';
    t[0]='b';
    cout<<s<<endl;
    cout<<t<<endl;
    
}
0