結果

問題 No.1909 Detect from Substrings
ユーザー wudi mawudi ma
提出日時 2022-04-24 01:57:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,099 bytes
コンパイル時間 7,066 ms
コンパイル使用メモリ 196,604 KB
実行使用メモリ 40,128 KB
最終ジャッジ日時 2023-09-07 17:19:00
合計ジャッジ時間 21,092 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,536 KB
testcase_01 AC 6 ms
11,580 KB
testcase_02 AC 5 ms
11,708 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 863 ms
39,524 KB
testcase_09 AC 805 ms
40,052 KB
testcase_10 AC 201 ms
24,032 KB
testcase_11 AC 183 ms
24,148 KB
testcase_12 WA -
testcase_13 AC 744 ms
39,792 KB
testcase_14 AC 740 ms
39,904 KB
testcase_15 AC 770 ms
40,072 KB
testcase_16 AC 87 ms
19,404 KB
testcase_17 AC 27 ms
13,440 KB
testcase_18 AC 24 ms
13,724 KB
testcase_19 AC 24 ms
13,608 KB
testcase_20 AC 25 ms
13,516 KB
testcase_21 AC 740 ms
39,928 KB
testcase_22 AC 787 ms
39,824 KB
testcase_23 AC 181 ms
24,440 KB
testcase_24 AC 204 ms
24,080 KB
testcase_25 AC 86 ms
19,348 KB
testcase_26 AC 786 ms
39,788 KB
testcase_27 AC 800 ms
39,528 KB
testcase_28 AC 743 ms
39,792 KB
testcase_29 AC 691 ms
40,128 KB
testcase_30 AC 749 ms
39,584 KB
testcase_31 AC 677 ms
39,800 KB
testcase_32 AC 774 ms
39,792 KB
testcase_33 AC 748 ms
39,792 KB
testcase_34 AC 785 ms
39,524 KB
testcase_35 AC 738 ms
39,664 KB
testcase_36 AC 696 ms
39,672 KB
testcase_37 AC 719 ms
39,536 KB
testcase_38 AC 806 ms
39,636 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:91:23: 警告: ‘pos1’ may be used uninitialized [-Wmaybe-uninitialized]
   91 |     for(int i = 0 ; i < pos1 ; i ++ ){
      |                     ~~^~~~~~
main.cpp:77:9: 備考: ‘pos1’ はここで定義されています
   77 |     int pos1,pos2;
      |         ^~~~

ソースコード

diff #

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
unsigned long long has[N],base[N];

unsigned long long get(int l,int r){
    if(r < l)return 0;
    return has[r] - has[l-1] * base[r-l+1];
}

unordered_map<unsigned long long,int>mp;
int main(){
    base[0] = 1;
    for(int i = 1 ; i < N ; i ++ )base[i] = base[i-1] * 131;
    int n,m;cin >> n >> m;
    vector<string>s(n);
    for(int i = 0 ; i < n ; i ++ ){
        cin >> s[i];
    }
    sort(s.begin(),s.end());
    s.resize(unique(s.begin(),s.end())-s.begin());
    if(s.size() == 1){
        return cout << (m+1) * 26,0;
    }   
    string ta = s[0] + s[1][s[1].size()-1];
    for(int i = 1 ; i <= m+1 ; i ++ ){
        has[i] = has[i-1] * 131 + ta[i-1];
    }
    for(int i = 1 ; i <= m+1 ; i ++ ){
        mp[get(1,i-1) * 131 + get(i+1,m+1)];
    }
    bool ok = 0;
    // cout << get(2,m+1) << '\n';
    mp[get(1,m)] = mp[get(2,m+1)] = 1;
    for(int i = 0 ; i < min(n,3) ; i ++ ){
        ok = 0;
        for(int j = 1 ; j <= m ; j ++ ){
            has[j] = has[j-1] * 131 + s[i][j-1];
        }
        // cout << get(1,2) << '\n';
        for(int j = 1 ; j <= m ; j ++ ){
            // cout << get(j,m) << '\n';
            if(mp.count(get(1,j-1) * 131 + get(j,m))){
                ok = 1;
                break;
            }
        }
        if(ok == 0)break;
    }
    if(ok){
        string tb = s[1][0] + s[0];
        mp.clear();
        for(int i = 1 ; i <= m+1 ; i ++ ){
            has[i] = has[i-1] * 131 + tb[i-1];
        }
        for(int i = 1 ; i <= m+1 ; i ++ ){
            mp[get(1,i-1) * 131 + get(i+1,m+1)];
        }
        mp[get(1,m)] = mp[get(2,m+1)] = 1;
        for(int i = 0 ; i < min(n,3) ; i ++ ){
            ok = 0;
            for(int j = 1 ; j <= m ; j ++ ){
                has[j] = has[j-1] * 131 + s[i][j-1];
            }
            for(int j = 1 ; j <= m ; j ++ ){
                if(mp.count(get(1,j-1) * 131 + get(j,m))){
                    ok = 1;
                    break;
                }
            }
            if(ok == 0)break;
        }
        if(ok)return cout << 2,0;
    }

    int pos1,pos2;
    for(int i = 0 ; i < m ; i ++ ){
        pos1 = i;
        if(s[0][i] != s[1][i])break;
    }
    for(int i = m-1 ; i > 0 ; i -- ){
        pos2 = i;
        if(s[0][i] != s[1][i])break;
    }
    ok = 0;
    for(int i = pos1 ; i < pos2 ; i ++ ){
        if(s[0][i] != s[1][i+1])ok = 1;
    }
    string x;
    for(int i = 0 ; i < pos1 ; i ++ ){
        x += s[0][i];
    }
    string y = x;
    // if(!ok){
        x += s[1][pos1];
        for(int i = pos1 ; i < s[0].size() ; i ++ )x += s[0][i];
    // }
    // else{
        y += s[0][pos1];
        for(int i = pos1 ; i < s[1].size() ; i ++ )y += s[1][i];
    // }
    mp.clear();
    for(int i = 1 ; i <= m+1 ; i ++ ){
        has[i] = has[i-1] * 131 + x[i-1];
    }
    for(int i = 1 ; i <= m+1 ; i ++ ){
        mp[get(1,i-1) * 131 + get(i+1,m+1)];
    }
    ok = 0;
    mp[get(1,m)] = mp[get(2,m+1)] = 1;
    for(int i = 0 ; i < min(n,3) ; i ++ ){
        ok = 0;
        for(int j = 1 ; j <= m ; j ++ ){
            has[j] = has[j-1] * 131 + s[i][j-1];
        }
        for(int j = 1 ; j <= m ; j ++ ){
            if(mp.count(get(1,j-1) * 131 + get(j,m))){
                ok = 1;
                break;
            }
        }
        if(ok == 0)break;
    }
    int res = ok;
    ok = 0;
    x = y;
    // cout << x << '\n';
    mp.clear();
    for(int i = 1 ; i <= m+1 ; i ++ ){
        has[i] = has[i-1] * 131 + x[i-1];
    }
    for(int i = 1 ; i <= m+1 ; i ++ ){
        mp[get(1,i-1) * 131 + get(i+1,m+1)];
    }
    ok = 0;
    mp[get(1,m)] = mp[get(2,m+1)] = 1;
    for(int i = 0 ; i < min(n,3) ; i ++ ){
        ok = 0;
        for(int j = 1 ; j <= m ; j ++ ){
            has[j] = has[j-1] * 131 + s[i][j-1];
        }
        for(int j = 1 ; j <= m ; j ++ ){
            if(mp.count(get(1,j-1) * 131 + get(j,m))){
                ok = 1;
                break;
            }
        }
        if(ok == 0)break;
    }
    res += ok;
    cout << res << '\n';
}
0