結果

問題 No.1909 Detect from Substrings
ユーザー wudi mawudi ma
提出日時 2022-04-24 01:44:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,360 bytes
コンパイル時間 2,550 ms
コンパイル使用メモリ 191,844 KB
実行使用メモリ 50,740 KB
最終ジャッジ日時 2024-06-25 10:56:52
合計ジャッジ時間 42,255 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,264 KB
testcase_01 AC 5 ms
11,264 KB
testcase_02 AC 6 ms
11,392 KB
testcase_03 AC 7 ms
11,392 KB
testcase_04 AC 10 ms
11,520 KB
testcase_05 AC 34 ms
12,416 KB
testcase_06 AC 62 ms
13,312 KB
testcase_07 AC 31 ms
13,312 KB
testcase_08 AC 1,680 ms
49,044 KB
testcase_09 AC 1,680 ms
49,052 KB
testcase_10 AC 469 ms
26,732 KB
testcase_11 AC 451 ms
26,860 KB
testcase_12 AC 245 ms
19,712 KB
testcase_13 AC 1,671 ms
49,052 KB
testcase_14 AC 1,662 ms
49,048 KB
testcase_15 AC 1,826 ms
49,048 KB
testcase_16 AC 288 ms
19,584 KB
testcase_17 AC 101 ms
13,440 KB
testcase_18 AC 72 ms
13,312 KB
testcase_19 WA -
testcase_20 AC 64 ms
13,312 KB
testcase_21 AC 1,730 ms
49,180 KB
testcase_22 AC 1,947 ms
49,048 KB
testcase_23 AC 567 ms
26,732 KB
testcase_24 AC 636 ms
26,736 KB
testcase_25 AC 325 ms
19,584 KB
testcase_26 AC 1,964 ms
49,048 KB
testcase_27 AC 1,752 ms
49,180 KB
testcase_28 AC 1,570 ms
49,176 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:91:23: warning: 'pos1' may be used uninitialized [-Wmaybe-uninitialized]
   91 |     for(int i = 0 ; i < pos1 ; i ++ ){
      |                     ~~^~~~~~
main.cpp:77:9: note: 'pos1' was declared here
   77 |     int pos1,pos2;
      |         ^~~~
main.cpp:87:26: warning: 'pos2' may be used uninitialized [-Wmaybe-uninitialized]
   87 |     for(int i = pos1 ; i < pos2 ; i ++ ){
      |                        ~~^~~~~~
main.cpp:77:14: note: 'pos2' was declared here
   77 |     int pos1,pos2;
      |              ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
map<int,int>st;
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];
}

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 < n ; 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 < n ; 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];
    }
    if(!ok){
        x += s[1][pos1];
        for(int i = pos1 ; i < s[0].size() ; i ++ )x += s[0][i];
    }
    else{
        x += s[0][pos1];
        for(int i = pos1 ; i < s[1].size() ; i ++ )x += s[1][i];
    }
    mp.clear();
    // cout << x << '\n';
    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 < n ; 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;
    }
    cout << ok;
}
0