結果

問題 No.2172 SEARCH in the Text Editor
ユーザー 👑 kmjpkmjp
提出日時 2022-12-24 00:21:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,661 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 202,096 KB
実行使用メモリ 94,664 KB
最終ジャッジ日時 2023-08-11 13:41:48
合計ジャッジ時間 6,884 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,376 KB
testcase_01 AC 4 ms
11,380 KB
testcase_02 AC 4 ms
11,404 KB
testcase_03 AC 84 ms
94,568 KB
testcase_04 AC 86 ms
94,568 KB
testcase_05 AC 85 ms
94,552 KB
testcase_06 AC 28 ms
61,560 KB
testcase_07 AC 21 ms
47,284 KB
testcase_08 AC 22 ms
49,372 KB
testcase_09 AC 38 ms
73,908 KB
testcase_10 AC 37 ms
69,788 KB
testcase_11 AC 45 ms
45,184 KB
testcase_12 AC 29 ms
63,632 KB
testcase_13 AC 35 ms
73,812 KB
testcase_14 AC 42 ms
88,268 KB
testcase_15 AC 26 ms
53,432 KB
testcase_16 AC 30 ms
69,808 KB
testcase_17 AC 27 ms
61,724 KB
testcase_18 AC 44 ms
86,292 KB
testcase_19 AC 36 ms
81,220 KB
testcase_20 AC 23 ms
50,728 KB
testcase_21 AC 69 ms
81,244 KB
testcase_22 AC 48 ms
94,444 KB
testcase_23 AC 48 ms
94,496 KB
testcase_24 AC 51 ms
94,604 KB
testcase_25 AC 50 ms
94,516 KB
testcase_26 AC 87 ms
94,444 KB
testcase_27 AC 87 ms
94,380 KB
testcase_28 AC 49 ms
94,520 KB
testcase_29 AC 48 ms
94,388 KB
testcase_30 AC 50 ms
94,392 KB
testcase_31 AC 50 ms
94,336 KB
testcase_32 AC 84 ms
94,484 KB
testcase_33 AC 85 ms
94,364 KB
testcase_34 AC 49 ms
94,664 KB
testcase_35 AC 49 ms
94,352 KB
testcase_36 AC 51 ms
94,448 KB
testcase_37 AC 50 ms
94,384 KB
testcase_38 AC 86 ms
94,584 KB
testcase_39 AC 87 ms
94,384 KB
testcase_40 AC 48 ms
94,300 KB
testcase_41 AC 47 ms
94,356 KB
testcase_42 AC 49 ms
94,348 KB
testcase_43 AC 48 ms
94,348 KB
testcase_44 AC 82 ms
93,844 KB
testcase_45 AC 82 ms
93,700 KB
testcase_46 AC 57 ms
61,536 KB
testcase_47 AC 46 ms
47,164 KB
testcase_48 AC 47 ms
49,312 KB
testcase_49 AC 66 ms
73,344 KB
testcase_50 AC 63 ms
69,376 KB
testcase_51 AC 43 ms
44,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------


int N,L;
string T,S[101010];
ll nex[101010][55];
ll num[101010][55];

int stt[1024][257];
const ll mo=998244353;
const char base='\0';
void CreateSTT(string& pat) {
	int x,y,z,l;
	ZERO(stt);
	l=pat.size();
	FOR(x,l+1) {
		FOR(y,256) {
			string pre=pat.substr(0,x)+(char)(base+y);
			for(z=1;z<=min(pat.size(),pre.size());z++) if(pre.substr(pre.size()-z) == pat.substr(0,z)) stt[x][y]=z;
		}
		if(x!=l) stt[x][y]=x+1;
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>T;
	L=T.size();
	CreateSTT(T);
	
	FOR(i,N) {
		cin>>s;
		if(s=="~") {
			cin>>x>>y;
			x--,y--;
			FOR(j,L+1) {
				nex[i][j]=nex[y][nex[x][j]];
				num[i][j]=(num[x][j]+num[y][nex[x][j]])%mo;
			}
		}
		else {
			FOR(j,L+1) {
				nex[i][j]=j;
				FORR(c,s) {
					nex[i][j]=stt[nex[i][j]][c];
					if(nex[i][j]==L) num[i][j]++;
				}
			}
		}
	}
	
	cout<<num[N-1][0]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0