結果

問題 No.1909 Detect from Substrings
ユーザー asaringoasaringo
提出日時 2022-05-29 17:47:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,853 bytes
コンパイル時間 2,605 ms
コンパイル使用メモリ 206,408 KB
実行使用メモリ 23,316 KB
最終ジャッジ日時 2023-10-21 00:02:42
合計ジャッジ時間 6,499 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
19,460 KB
testcase_01 AC 6 ms
19,460 KB
testcase_02 AC 7 ms
19,460 KB
testcase_03 AC 7 ms
19,484 KB
testcase_04 AC 9 ms
19,656 KB
testcase_05 AC 17 ms
20,412 KB
testcase_06 AC 27 ms
21,364 KB
testcase_07 AC 27 ms
21,360 KB
testcase_08 AC 31 ms
22,192 KB
testcase_09 AC 29 ms
21,172 KB
testcase_10 AC 27 ms
20,996 KB
testcase_11 AC 28 ms
20,872 KB
testcase_12 AC 27 ms
20,536 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 35 ms
23,248 KB
testcase_31 WA -
testcase_32 AC 34 ms
23,248 KB
testcase_33 WA -
testcase_34 AC 33 ms
23,248 KB
testcase_35 WA -
testcase_36 AC 34 ms
23,248 KB
testcase_37 WA -
testcase_38 AC 38 ms
23,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef pair<ll,ll> P ;
typedef tuple<bool,ll,ll,ll> TP ;
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
#define bit_count(x) __builtin_popcountll(x)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / gcd(a,b) * b
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rrep(i,a,b) for(int i = a ; i < b ; i++)
#define endl "\n"
#define a_z "abcdefghijklmnopqrstuvwxyz"

int n , m ;
string S[505050] ;
vector<string> vec ;

int main(){
    cin >> n >> m ;
    rep(i,n) cin >> S[i] ;
    string s = S[0] ;
    string t = S[1] ;
    string a = "" , b = "" ;
    int i = 0 , j = 0 ;
    bool use_a = false , use_b = false ;
    while(true){
        if(i == m && j == m) break;
        if(i == m){
            a += t[j] ;
            b += t[j] ;
            j++ ;
        }
        else if(j == m){
            a += s[i] ;
            b += s[i] ;
            i++ ;
        }
        else if(s[i] != t[j]){
            if(s[i+1] == t[j+1] && !use_a && !use_b){
                a += s[i] ;
                a += t[j] ;
                b += t[j] ;
                b += s[i] ;
                use_a = true ;
                use_b = true ;
                i++ ;
                j++ ;
            }
            else if(s[i+1] == t[i] && t[i+1] == s[i] && !use_a && !use_b){
                a += s[i] ;
                a += t[j] ;
                a += t[j+1] ;
                b += t[j] ;
                b += s[i] ;
                b += s[i+1] ;
                use_a = true ;
                use_b = true ;
                i+=2 ;
                j+=2 ;
            }
            else if(s[i+1] == t[i] && !use_a) a += s[i] , b += s[i] , i++ , use_a = true ;
            else if(t[j+1] == s[j] && !use_b) b += t[j] , a += t[j] , j++ , use_b = true ;
            else{
                cout << 0 << endl ;
                return 0 ;
            }
        }
        else{
            a += s[i] ;
            b += t[j] ;
            i++ ;
            j++ ;
        }
    }
    bool ok = a == b ? true : false ;
    bool ga = true , gb = true ;
    int res = 2 ;
    rep(i,n){
        int ida = 0 ;
        if(ga) rep(j,m){
            if(!ga) break;
            while(a[ida] != S[i][j]){
                ida++ ;
                if(ida == 2){
                    ga = false ;
                    break ;
                }
            }
            ida++ ;
        }
        int idb = 0 ;
        if(gb) rep(j,m){
            if(!gb) break;
            while(a[idb] != S[i][j]){
                idb++ ;
                if(idb == 2){
                    gb = false ;
                    break ;
                }
            }
            idb++ ;
        }
    }
    if(!ga) res-- ;
    if(!gb) res-- ;
    if(res == 2 && ok) res = 1 ;
    cout << res << endl ;
}
0