結果

問題 No.2172 SEARCH in the Text Editor
ユーザー KudeKude
提出日時 2022-12-24 01:16:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,312 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 228,332 KB
実行使用メモリ 14,032 KB
最終ジャッジ日時 2024-04-29 06:07:52
合計ジャッジ時間 10,462 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 RE -
testcase_04 AC 41 ms
13,952 KB
testcase_05 RE -
testcase_06 AC 12 ms
9,088 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 15 ms
7,116 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 13 ms
9,856 KB
testcase_17 WA -
testcase_18 AC 18 ms
12,008 KB
testcase_19 WA -
testcase_20 AC 10 ms
7,920 KB
testcase_21 AC 26 ms
11,648 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;

int m;
struct S {
  bool first_ok[50]{}, second_ok[50]{};
  mint cnt;
  int len = 0;
  friend S operator*(S x, S y) {
    S z;
    z.cnt = x.cnt + y.cnt;
    z.len = x.len + y.len;
    for(int i = 1; i < m; i++) if (x.first_ok[i] && y.second_ok[i]) {
      if (i <= x.len) {
        if (i + y.len >= m) {
          z.cnt++;
        } else {
          z.first_ok[i + y.len] = true;
        }
      } else {
        z.second_ok[i - x.len] = true;
        if (i + y.len < m) z.first_ok[i + y.len] = true;
      }
    }
    for(int i = 1; i < m; i++) if (m - i < x.len) z.second_ok[i] = x.second_ok[i];
    for(int i = 1; i < m; i++) if (i < y.len) z.first_ok[i] = y.first_ok[i];
    return z;
  }
};

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string t;
  cin >> t;
  m = t.size();
  vector<S> d(n);
  rep(z, n) {
    string s;
    cin >> s;
    if (s[0] == '~') {
      int j, k;
      cin >> j >> k;
      j--, k--;
      d[z] = d[j] * d[k];
    } else {
      S A;
      int sz = s.size();
      A.len = sz;
      auto chk = [&](int p1, int p2) {
        while(p1 < m && p2 < sz) if (t[p1++] != s[p2++]) return false;
        return true;
      };
      for(int i = 1; i < m; i++) if (chk(i, 0)) {
        A.second_ok[i] = true;
        if (i + sz < m) A.first_ok[i + sz] = true;
      }
      for(int p = 0; p < sz; p++) if (chk(0, p)) {
        if (sz - p >= m) A.cnt++;
        else A.first_ok[sz - p] = true;
      }
      d[z] = A;
    }
  }
  mint ans = d[n - 1].cnt;
  cout << ans.val() << '\n';
}
0