結果
問題 | No.2172 SEARCH in the Text Editor |
ユーザー | Kude |
提出日時 | 2022-12-24 01:45:33 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 2,318 bytes |
コンパイル時間 | 2,195 ms |
コンパイル使用メモリ | 232,284 KB |
実行使用メモリ | 31,992 KB |
最終ジャッジ日時 | 2024-04-29 06:08:19 |
合計ジャッジ時間 | 5,494 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 89 ms
31,864 KB |
testcase_04 | AC | 93 ms
31,852 KB |
testcase_05 | AC | 84 ms
31,792 KB |
testcase_06 | AC | 13 ms
6,944 KB |
testcase_07 | AC | 10 ms
6,940 KB |
testcase_08 | AC | 11 ms
6,940 KB |
testcase_09 | AC | 21 ms
8,448 KB |
testcase_10 | AC | 19 ms
8,192 KB |
testcase_11 | AC | 12 ms
6,944 KB |
testcase_12 | AC | 13 ms
7,040 KB |
testcase_13 | AC | 17 ms
7,936 KB |
testcase_14 | AC | 23 ms
8,960 KB |
testcase_15 | AC | 14 ms
6,940 KB |
testcase_16 | AC | 13 ms
7,424 KB |
testcase_17 | AC | 12 ms
6,944 KB |
testcase_18 | AC | 21 ms
9,384 KB |
testcase_19 | AC | 16 ms
8,400 KB |
testcase_20 | AC | 11 ms
6,944 KB |
testcase_21 | AC | 25 ms
9,856 KB |
testcase_22 | AC | 28 ms
10,104 KB |
testcase_23 | AC | 30 ms
10,084 KB |
testcase_24 | AC | 29 ms
10,184 KB |
testcase_25 | AC | 29 ms
9,996 KB |
testcase_26 | AC | 85 ms
31,776 KB |
testcase_27 | AC | 78 ms
31,764 KB |
testcase_28 | AC | 21 ms
9,728 KB |
testcase_29 | AC | 24 ms
9,760 KB |
testcase_30 | AC | 22 ms
9,864 KB |
testcase_31 | AC | 23 ms
9,708 KB |
testcase_32 | AC | 26 ms
9,936 KB |
testcase_33 | AC | 25 ms
9,744 KB |
testcase_34 | AC | 28 ms
10,032 KB |
testcase_35 | AC | 30 ms
10,028 KB |
testcase_36 | AC | 29 ms
9,984 KB |
testcase_37 | AC | 30 ms
9,940 KB |
testcase_38 | AC | 94 ms
31,896 KB |
testcase_39 | AC | 91 ms
31,992 KB |
testcase_40 | AC | 22 ms
9,924 KB |
testcase_41 | AC | 23 ms
9,832 KB |
testcase_42 | AC | 21 ms
9,740 KB |
testcase_43 | AC | 23 ms
9,840 KB |
testcase_44 | AC | 22 ms
9,800 KB |
testcase_45 | AC | 22 ms
9,804 KB |
testcase_46 | AC | 18 ms
7,808 KB |
testcase_47 | AC | 14 ms
6,944 KB |
testcase_48 | AC | 15 ms
6,940 KB |
testcase_49 | AC | 20 ms
9,088 KB |
testcase_50 | AC | 20 ms
8,832 KB |
testcase_51 | AC | 12 ms
6,940 KB |
ソースコード
#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; template <class T> vector<int> KMP(const T& pattern) { const int n = pattern.size(); vector<int> pi(n + 1); pi[0] = -1; int border = 0; for (int i = 1; i < n; i++, border++) { const auto c = pattern[i]; if (pattern[border] == c) { pi[i] = pi[border]; } else { pi[i] = border; while (border != -1 && pattern[border] != c) { border = pi[border]; } } } pi[n] = border; return pi; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string t; cin >> t; int m = t.size(); VI kmp = KMP(t); vector<string> head(n), tail(n); vector<mint> cnt(n); rep(i, n) { string s; cin >> s; if (s[0] == '~') { int j, k; cin >> j >> k; j--, k--; cnt[i] = cnt[j] + cnt[k]; int p = 0; for(char c: tail[j]) { while(p != -1 && t[p] != c) p = kmp[p]; p++; if (p == m) p = kmp[p]; } for(char c: head[k]) { while(p != -1 && t[p] != c) p = kmp[p]; p++; if (p == m) cnt[i]++, p = kmp[p]; } head[i] = head[j] + head[k]; tail[i] = tail[j] + tail[k]; } else { int p = 0; for(char c: s) { while(p != -1 && t[p] != c) p = kmp[p]; p++; if (p == m) cnt[i]++, p = kmp[p]; } head[i] = s; tail[i] = s; } if (int(head[i].size()) >= m) head[i].resize(m - 1); if (int(tail[i].size()) >= m) tail[i].erase(tail[i].begin(), tail[i].end() - (m - 1)); } cout << cnt[n - 1].val() << '\n'; }