結果

問題 No.2172 SEARCH in the Text Editor
ユーザー lddlinanlddlinan
提出日時 2023-03-28 19:40:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 2,365 bytes
コンパイル時間 853 ms
コンパイル使用メモリ 87,628 KB
実行使用メモリ 14,072 KB
最終ジャッジ日時 2023-10-20 13:00:31
合計ジャッジ時間 6,861 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,260 KB
testcase_01 AC 3 ms
7,260 KB
testcase_02 AC 3 ms
5,212 KB
testcase_03 AC 56 ms
14,072 KB
testcase_04 AC 60 ms
14,072 KB
testcase_05 AC 56 ms
14,072 KB
testcase_06 AC 12 ms
5,212 KB
testcase_07 AC 15 ms
12,024 KB
testcase_08 AC 14 ms
12,024 KB
testcase_09 AC 28 ms
14,072 KB
testcase_10 AC 26 ms
14,072 KB
testcase_11 AC 16 ms
12,024 KB
testcase_12 AC 20 ms
14,072 KB
testcase_13 AC 24 ms
14,072 KB
testcase_14 AC 31 ms
14,072 KB
testcase_15 AC 20 ms
12,024 KB
testcase_16 AC 13 ms
5,212 KB
testcase_17 AC 19 ms
14,072 KB
testcase_18 AC 31 ms
14,072 KB
testcase_19 AC 25 ms
14,072 KB
testcase_20 AC 15 ms
12,024 KB
testcase_21 AC 29 ms
14,072 KB
testcase_22 AC 32 ms
14,072 KB
testcase_23 AC 32 ms
14,072 KB
testcase_24 AC 33 ms
14,072 KB
testcase_25 AC 33 ms
14,072 KB
testcase_26 AC 55 ms
14,072 KB
testcase_27 AC 55 ms
14,072 KB
testcase_28 AC 31 ms
14,072 KB
testcase_29 AC 33 ms
14,072 KB
testcase_30 AC 33 ms
14,072 KB
testcase_31 AC 33 ms
14,072 KB
testcase_32 AC 35 ms
14,072 KB
testcase_33 AC 36 ms
14,072 KB
testcase_34 AC 32 ms
14,072 KB
testcase_35 AC 32 ms
14,072 KB
testcase_36 AC 34 ms
14,072 KB
testcase_37 AC 33 ms
14,072 KB
testcase_38 AC 60 ms
14,072 KB
testcase_39 AC 57 ms
14,072 KB
testcase_40 AC 32 ms
14,072 KB
testcase_41 AC 33 ms
14,072 KB
testcase_42 AC 33 ms
14,072 KB
testcase_43 AC 33 ms
14,072 KB
testcase_44 AC 32 ms
14,072 KB
testcase_45 AC 33 ms
14,072 KB
testcase_46 AC 22 ms
14,072 KB
testcase_47 AC 17 ms
12,024 KB
testcase_48 AC 17 ms
12,024 KB
testcase_49 AC 26 ms
14,072 KB
testcase_50 AC 25 ms
14,072 KB
testcase_51 AC 15 ms
12,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
class mypcmp {
public:
    bool operator()(const int& a, const int& b) {
        return a<b;
    }
};


#define MOD 998244353
char it[128];
int ff[128];
char ib[100004];
int cc[100004];
char ssc[100004], esc[100004];
char ss[100004][52];
char es[100004][52];
int main() {
    int n, i, j, m, f, c, a, b, k;
    scanf("%d", &n);
    scanf("%s", it);
    f=-1; for (m=0;;m++) {
        ff[m]=f;
        while(f!=-1&&it[f]!=it[m]) f=ff[f]; f++;
        if (it[m]==0) break;
    }
    for (i=0; i<n; i++) {
        scanf("%s", ib);
        if (ib[0]=='~') {
            scanf("%d %d", &a, &b); a--; b--;
            c=cc[a]+cc[b];
            // printf("merge %d,%d, start : %d\n", a, b, c);
            f=0;
            for (j=0; j<esc[a]; j++) {
                while(f!=-1&&it[f]!=es[a][esc[a]-1-j]) f=ff[f]; f++;
            }
            for (j=0; j<ssc[b]; j++) {
                while(f!=-1&&it[f]!=ss[b][j]) f=ff[f]; f++;
                if (f>=m) c++;
            }
            c%=MOD;
            cc[i]=c;
            //
            for (j=0; j<ssc[a]; j++) ss[i][j]=ss[a][j]; c=ssc[a];
            for (j=0; j<ssc[b]&&c<m-1; j++, c++) ss[i][c]=ss[b][j];
            ssc[i]=c;
            for (j=0; j<esc[b]; j++) es[i][j]=es[b][j]; c=esc[b];
            for (j=0; j<esc[a]&&c<m-1; j++, c++) es[i][c]=es[a][j];
            esc[i]=c;
        } else {
            c=0; f=0;
            for (j=0; ib[j]; j++) {
                while(f!=-1&&it[f]!=ib[j]) f=ff[f];
                f++;
                if (f>=m) c++;
            }
            cc[i]=c%MOD;
            if (j>=m) {
                ssc[i]=m-1; esc[i]=m-1; 
                for (k=0; k<m-1; k++) {
                    ss[i][k]=ib[k];
                    es[i][k]=ib[j-1-k];
                }
            } else {
                ssc[i]=j; esc[i]=j;
                for (k=0; k<j; k++) {
                    ss[i][k]=ib[k];
                    es[i][k]=ib[j-1-k];
                }
            }
        }
    }
    printf("%d\n", cc[n-1]);
    return 0;
}
0