結果
| 問題 | 
                            No.2172 SEARCH in the Text Editor
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-12-24 05:00:36 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 928 bytes | 
| コンパイル時間 | 1,520 ms | 
| コンパイル使用メモリ | 172,964 KB | 
| 実行使用メモリ | 22,980 KB | 
| 最終ジャッジ日時 | 2024-11-18 07:17:07 | 
| 合計ジャッジ時間 | 5,115 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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,m);
			}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=x.size(),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;
}