結果
| 問題 | 
                            No.2172 SEARCH in the Text Editor
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-12-24 06:06:42 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 958 bytes | 
| コンパイル時間 | 1,834 ms | 
| コンパイル使用メモリ | 172,532 KB | 
| 実行使用メモリ | 22,968 KB | 
| 最終ジャッジ日時 | 2024-11-18 07:17:19 | 
| 合計ジャッジ時間 | 5,352 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 37 WA * 12 | 
ソースコード
#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){
	ll i,j;
	cin.tie(0);  ios_base::sync_with_stdio(false);
	ll N;
	string T;
	cin >> N >> T;
	ll n=T.size();
	for(i=1;i<=N;i++){
		string s;
		cin >> s;
		ll m=s.size();
		if(s!="~"){
			for(j=0;j<=m-n;j++) if(T==s.substr(j,n)){
				c[i]++;
				c[i]%=MOD;
			}
			if(m>=n-1){
				b[i]=s.substr(0,n-1);
				a[i]=s.substr(m-n+1,n-1);
			}else{
				b[i]=s;
				a[i]=s;
			}
		}else{
			ll J,K;
			cin >> J >> K;
			b[i]=b[J];
			a[i]=a[K];
			string x=a[J];
			x+=b[K];
			ll p=b[J].size(),q=a[K].size(),d=0;
			if(p+q>=n){
				for(j=0;j<p;j++) if(j<=p+q-n && T==x.substr(j,n)) d++;
				c[i]=c[J]+c[K]+d;
				c[i]%=MOD;
			}else{
				c[i]=c[J]+c[K];
				c[i]%=MOD;
			}
		}
		if(i==N) cout << c[N] << endl;
	}
	return 0;
}