結果

問題 No.1909 Detect from Substrings
ユーザー RubikunRubikun
提出日時 2022-04-22 21:20:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,569 bytes
コンパイル時間 2,389 ms
コンパイル使用メモリ 210,272 KB
実行使用メモリ 7,148 KB
最終ジャッジ日時 2023-09-06 07:36:01
合計ジャッジ時間 4,563 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 7 ms
4,524 KB
testcase_07 AC 7 ms
4,452 KB
testcase_08 AC 5 ms
5,116 KB
testcase_09 AC 5 ms
5,332 KB
testcase_10 AC 8 ms
4,612 KB
testcase_11 AC 5 ms
4,540 KB
testcase_12 AC 8 ms
4,564 KB
testcase_13 AC 10 ms
6,076 KB
testcase_14 AC 10 ms
5,656 KB
testcase_15 AC 11 ms
5,816 KB
testcase_16 AC 8 ms
4,628 KB
testcase_17 AC 7 ms
4,384 KB
testcase_18 AC 7 ms
4,376 KB
testcase_19 AC 8 ms
4,628 KB
testcase_20 AC 7 ms
4,448 KB
testcase_21 AC 10 ms
5,508 KB
testcase_22 AC 9 ms
5,332 KB
testcase_23 AC 9 ms
4,784 KB
testcase_24 AC 8 ms
4,596 KB
testcase_25 AC 8 ms
4,528 KB
testcase_26 AC 10 ms
5,852 KB
testcase_27 AC 10 ms
5,728 KB
testcase_28 AC 10 ms
5,540 KB
testcase_29 AC 15 ms
5,596 KB
testcase_30 AC 15 ms
7,120 KB
testcase_31 AC 14 ms
5,916 KB
testcase_32 AC 15 ms
6,752 KB
testcase_33 AC 15 ms
6,088 KB
testcase_34 AC 15 ms
7,080 KB
testcase_35 AC 14 ms
5,784 KB
testcase_36 AC 15 ms
7,068 KB
testcase_37 AC 14 ms
5,832 KB
testcase_38 AC 15 ms
7,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    vector<string> S(N);
    for(int i=0;i<N;i++) cin>>S[i];
    string A=S[0],B=S[1];
    int i=0;
    while(i<M&&A[i]==B[i]) i++;
    int j=M-1;
    while(j>=0&&A[j]==B[j]) j--;
    
    set<string> SE;
    
    A=A.substr(i,j-i+1);
    B=B.substr(i,j-i+1);
    if(A.substr(1)==B.substr(0,si(B)-1)){
        string C=S[0].substr(0,i)+A+B.back()+S[0].substr(j+1);
        bool f=true;
        for(int i=0;i<N;i++){
            int k=0;
            for(char c:C){
                if(k<si(S[i])&&S[i][k]==c) k++;
            }
            if(k<si(S[i])) f=false;
        }
        if(f) SE.insert(C);
    }
    if(B.substr(1)==A.substr(0,si(A)-1)){
        string D=S[0].substr(0,i)+B+A.back()+S[0].substr(j+1);
        bool f=true;
        for(int i=0;i<N;i++){
            int k=0;
            for(char c:D){
                if(k<si(S[i])&&S[i][k]==c) k++;
            }
            if(k<si(S[i])) f=false;
        }
        if(f) SE.insert(D);
    }
    
    cout<<si(SE)<<endl;
}
0