結果

問題 No.2172 SEARCH in the Text Editor
ユーザー tnakao0123tnakao0123
提出日時 2022-12-27 14:23:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 407 ms / 2,000 ms
コード長 2,380 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 59,092 KB
実行使用メモリ 51,108 KB
最終ジャッジ日時 2023-08-14 05:33:58
合計ジャッジ時間 7,067 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,416 KB
testcase_01 AC 5 ms
10,468 KB
testcase_02 AC 5 ms
10,376 KB
testcase_03 AC 407 ms
51,108 KB
testcase_04 AC 31 ms
10,448 KB
testcase_05 AC 45 ms
16,800 KB
testcase_06 AC 16 ms
10,388 KB
testcase_07 AC 18 ms
11,704 KB
testcase_08 AC 19 ms
11,756 KB
testcase_09 AC 40 ms
14,400 KB
testcase_10 AC 38 ms
14,640 KB
testcase_11 AC 38 ms
15,656 KB
testcase_12 AC 22 ms
11,636 KB
testcase_13 AC 27 ms
11,932 KB
testcase_14 AC 37 ms
13,096 KB
testcase_15 AC 24 ms
12,044 KB
testcase_16 AC 20 ms
10,400 KB
testcase_17 AC 20 ms
11,240 KB
testcase_18 AC 36 ms
12,856 KB
testcase_19 AC 23 ms
10,536 KB
testcase_20 AC 15 ms
10,452 KB
testcase_21 AC 36 ms
10,768 KB
testcase_22 AC 46 ms
16,752 KB
testcase_23 AC 46 ms
16,724 KB
testcase_24 AC 46 ms
16,704 KB
testcase_25 AC 45 ms
16,724 KB
testcase_26 AC 46 ms
16,720 KB
testcase_27 AC 46 ms
16,736 KB
testcase_28 AC 48 ms
15,524 KB
testcase_29 AC 50 ms
15,908 KB
testcase_30 AC 53 ms
16,644 KB
testcase_31 AC 52 ms
15,640 KB
testcase_32 AC 106 ms
26,128 KB
testcase_33 AC 110 ms
26,840 KB
testcase_34 AC 30 ms
10,408 KB
testcase_35 AC 46 ms
16,660 KB
testcase_36 AC 46 ms
16,684 KB
testcase_37 AC 38 ms
13,624 KB
testcase_38 AC 31 ms
10,444 KB
testcase_39 AC 46 ms
16,684 KB
testcase_40 AC 35 ms
12,404 KB
testcase_41 AC 36 ms
12,608 KB
testcase_42 AC 37 ms
12,372 KB
testcase_43 AC 35 ms
12,376 KB
testcase_44 AC 49 ms
11,860 KB
testcase_45 AC 49 ms
11,840 KB
testcase_46 AC 40 ms
13,860 KB
testcase_47 AC 30 ms
13,024 KB
testcase_48 AC 32 ms
13,140 KB
testcase_49 AC 38 ms
12,204 KB
testcase_50 AC 37 ms
12,156 KB
testcase_51 AC 22 ms
11,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2172.cc:  No.2172 SEARCH in the Text Editor - yukicoder
 */

#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 50;
const int MAX_L = 100000;
const int MOD = 998244353;

/* typedef */

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* typedef */

template<const int MOD>
struct MI {
  int v;
  MI(): v() {}
  MI(int _v): v(_v % MOD) {}
  MI(long long _v): v(_v % MOD) {}

  MI operator+(const MI m) const { return MI(v + m.v); }
  MI operator-(const MI m) const { return MI(v + MOD - m.v); }
  MI operator*(const MI m) const { return MI((long long)v * m.v); }

  MI &operator+=(const MI m) { return (*this = *this + m); }
  MI &operator-=(const MI m) { return (*this = *this - m); }
  MI &operator*=(const MI m) { return (*this = *this * m); }

  bool operator==(const MI m) const { return v == m.v; }
  bool operator!=(const MI m) const { return v != m.v; }
};

typedef MI<MOD> mi;

/* global variables */

char t[MAX_M + 4], s[MAX_L + 4];
mi ks[MAX_N];
vi hms[MAX_N], tms[MAX_N];
vpii mms[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d%s", &n, t);
  int m = strlen(t);

  for (int i = 0; i < n; i++) {
    scanf("%s", s);

    if (s[0] == '~') {
      int i0, i1;
      scanf("%d%d", &i0, &i1);
      i0--, i1--;

      ks[i] = ks[i0] + ks[i1];
      hms[i] = hms[i1];
      tms[i] = tms[i0];

      for (auto hj: hms[i0])
	for (auto tj: tms[i1])
	  if (hj == tj) ks[i] += 1;

      for (auto hj: hms[i0])
	for (auto me: mms[i1])
	  if (hj == me.first) hms[i].push_back(me.second);
      for (auto tj: tms[i1])
	for (auto me: mms[i0])
	  if (tj == me.second) tms[i].push_back(me.first);
	for (auto me0: mms[i0])
	  for (auto me1: mms[i1])
	    if (me0.second == me1.first)
	      mms[i].push_back(pii(me0.first, me1.second));
    }
    else {
      int l = strlen(s);
      for (int j = 0; j + m <= l; j++)
	if (! strncmp(s + j, t, m)) ks[i] += 1;

      for (int j = 1; j < m; j++) {
	if (j <= l && ! strncmp(s + l - j, t, j))
	  hms[i].push_back(j);
	if (m - j <= l && ! strncmp(s, t + j, m - j))
	  tms[i].push_back(j);
	if (j + l < m && ! strncmp(t + j, s, l))
	  mms[i].push_back(pii(j, j + l));
      }
    }
  }

  printf("%d\n", ks[n - 1].v);

  return 0;
}
0