結果

問題 No.2172 SEARCH in the Text Editor
ユーザー KudeKude
提出日時 2022-12-24 01:18:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,336 bytes
コンパイル時間 2,474 ms
コンパイル使用メモリ 227,884 KB
実行使用メモリ 13,952 KB
最終ジャッジ日時 2024-04-29 06:07:59
合計ジャッジ時間 5,983 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 51 ms
13,952 KB
testcase_04 AC 43 ms
13,952 KB
testcase_05 AC 43 ms
13,824 KB
testcase_06 AC 16 ms
8,960 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 20 ms
7,040 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 19 ms
9,856 KB
testcase_17 WA -
testcase_18 AC 29 ms
12,032 KB
testcase_19 WA -
testcase_20 AC 14 ms
7,936 KB
testcase_21 AC 37 ms
11,648 KB
testcase_22 AC 33 ms
13,824 KB
testcase_23 AC 35 ms
13,696 KB
testcase_24 AC 34 ms
13,824 KB
testcase_25 AC 34 ms
13,824 KB
testcase_26 AC 43 ms
13,696 KB
testcase_27 AC 43 ms
13,696 KB
testcase_28 AC 30 ms
13,824 KB
testcase_29 AC 31 ms
13,824 KB
testcase_30 AC 31 ms
13,696 KB
testcase_31 AC 31 ms
13,824 KB
testcase_32 AC 52 ms
13,824 KB
testcase_33 AC 52 ms
13,824 KB
testcase_34 AC 32 ms
13,824 KB
testcase_35 AC 33 ms
13,824 KB
testcase_36 AC 33 ms
13,696 KB
testcase_37 AC 33 ms
13,824 KB
testcase_38 AC 42 ms
13,696 KB
testcase_39 AC 43 ms
13,696 KB
testcase_40 AC 30 ms
13,824 KB
testcase_41 AC 30 ms
13,824 KB
testcase_42 AC 30 ms
13,696 KB
testcase_43 AC 31 ms
13,824 KB
testcase_44 AC 46 ms
13,696 KB
testcase_45 AC 46 ms
13,696 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
    chmin(z.len, 1000);
    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