結果

問題 No.2172 SEARCH in the Text Editor
ユーザー daiota
提出日時 2022-12-24 04:35:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 908 bytes
コンパイル時間 1,799 ms
コンパイル使用メモリ 171,504 KB
実行使用メモリ 22,980 KB
最終ジャッジ日時 2024-11-18 07:15:19
合計ジャッジ時間 6,293 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
typedef long long ll;
typedef pair<int,int> P;

const ll MOD=998244353;
ll c[100010];
string b[100010],a[100010];

int main(void){
	int i,j;

	cin.tie(0);  ios_base::sync_with_stdio(false);

	int N;
	string T;
	cin >> N >> T;

	int n=T.size();

	for(i=1;i<=N;i++){
		string s;
		cin >> s;

		int m=s.size();
		if(s!="~"){

			for(j=0;j<=m-n;j++) if(T==s.substr(j,n)){
				c[i]++;
				c[i]%=MOD;
			}

			b[i]=s.substr(0,min(n-1,m));
			a[i]=s.substr(max(0,m-n+1),min(n-1,m));

		}else{

			int J,K;
			cin >> J >> K;

			b[i]=b[J];
			a[i]=a[K];

			string x=a[J];
			x+=b[K];

			int p=x.size();
			ll q=0;
			if(p>=n){
				for(j=0;j<=p-n;j++) if(T==x.substr(j,n)) q++;
				c[i]=c[J]+c[K]+q;
				c[i]%=MOD;
			}else{
				c[i]=c[J]+c[K];
				c[i]%=MOD;
			}


		}

		if(i==N) cout << c[N] << endl;


	}

	return 0;
}
0