蜜汁RE10pts求助

P3121 [USACO15FEB] Censoring G

@[luoyx](/user/520056) 代码呢?
by cool_xu @ 2023-08-17 20:18:55


@[luoyx](/user/520056) 话说你要不挂一下你的代码?
by Tokai__Teio @ 2023-08-17 20:18:58


``` cpp #include <bits/stdc++.h> using namespace std; int n; const int N=2e6+5; char s[N],t[N]; int fail[N],tr[N][30],_end[N],tot; void insert(char s[]){ int p=0; int len; for(int i=1;s[i];i++){ int c=s[i]-'a'; if(!tr[p][c]) tr[p][c]=++tot; p=tr[p][c]; len=i; } _end[p]=len; } void build(){ queue<int> q; for(int i=0;i<26;i++){ if(tr[0][i]) q.push(tr[0][i]); } while(!q.empty()){ int u=q.front(); q.pop(); for(int i=0;i<26;i++){ int &v=tr[u][i]; if(v) fail[v]=tr[fail[u]][i],q.push(v); else v=tr[fail[u]][i]; } } } stack<int> st,st2; void solve(){ int p=0; int i=1; for(;s[i];i++){ int c=s[i]-'a'; p=tr[p][c]; st.push(p); st2.push(i); if(_end[p]){ for(int j=1;j<=_end[p];j++){ if(!st.empty()) st.pop(); if(!st2.empty()) st2.pop(); } if(st.empty()) p=0; else p=st.top(); } } } int main(){ n=1; cin>>s+1; cin>>n; for(int i=1;i<=n;i++){ cin>>t+1; insert(t); } build(); solve(); stack<int> st3; while(!st2.empty()){ st3.push(st2.top()); st2.pop(); } while(!st3.empty()){ cout<<s[st3.top()]; st3.pop(); } } ```
by luoyx @ 2023-08-17 20:21:29


@[luoyx](/user/520056) 你这该不会炸了吧
by Tokai__Teio @ 2023-08-17 20:25:41


@[luoyx](/user/520056) 要不把2e6换成1e6试试?
by Tokai__Teio @ 2023-08-17 20:27:22


@[ikura](/user/1003652) 还是 RE
by luoyx @ 2023-08-17 20:30:59


@[luoyx](/user/520056) N太大了吗?
by cool_xu @ 2023-08-17 20:33:30


话说这道题是不是能用 $find()$ 和 $erase()$ 写(蒟蒻的思考
by cool_xu @ 2023-08-17 20:35:05


@[cool_xu](/user/937661) 可以搞过去,但这样不就没意思了吗
by luoyx @ 2023-08-18 08:00:12


@[luoyx](/user/520056) 不愧是巨佬,和我这个蒟蒻就是不一样
by cool_xu @ 2023-08-18 09:52:55


|