QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#352561#7994. 勿蹖宠物zyz07WA 1ms4184kbC++172.6kb2024-03-13 12:45:372024-03-13 12:45:38

Judging History

你现在查看的是最新测评结果

  • [2024-03-13 12:45:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4184kb
  • [2024-03-13 12:45:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define For(Ti,Ta,Tb) for(auto Ti=(Ta);Ti<=(Tb);++Ti)
#define Dec(Ti,Ta,Tb) for(auto Ti=(Ta);Ti>=(Tb);--Ti)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define range(Tx) begin(Tx),end(Tx)
using ll=long long;
bool palin(string s){
	string t=s;
	reverse(range(t));
	return s==t;
}
const int N=340,L=1005,Mod=1e9+7;
int n,len,m[N],pre[N][L],suf[N][L];
char s[N][L],rs[N][L];
vector<int> trans1[L],trans2[L];
struct Trie{
	int ch[L][26],dep[L],tot,anc[L][L];
	bool palin[L];
	vector<int> id[L],sub[L];
	void insert(int cur_id,char* s,int* pre){
		int len=strlen(s+1),u=0;
		sub[0].push_back(cur_id);
		For(i,1,len){
			int& v=ch[u][s[i]-'a'];
			if(!v){
				v=++tot;
				dep[v]=dep[u]+1;
				anc[v][1]=u;
			}
			pre[i]=u=v;
			if(i<len) sub[v].push_back(cur_id);
		}
		id[u].push_back(cur_id);
	}
	char cur[L];
	void dfs(int u,vector<int>* trans){
		// debug("%d %s: ",u,cur+1);
		palin[u]=::palin(string(cur+1,cur+dep[u]+1));
		For(i,2,dep[u]){
			anc[u][i]=anc[anc[u][1]][i-1];
		}
		int x=0;
		Dec(i,dep[u],1){
			x=ch[x][cur[i]-'a'];
			if(!x){
				x=-1;
				break;
			}
			trans[u].insert(trans[u].end(),range(id[x]));
		}
		if(~x){
			trans[u].insert(trans[u].end(),range(sub[x]));
		}
		// for(int v:trans[u]){
		// 	debug("%d ",v);
		// }
		// debug("\n");
		For(i,0,25){
			if(ch[u][i]){
				cur[dep[u]+1]=i+'a';
				dfs(ch[u][i],trans);
				cur[dep[u]+1]=0;
			}
		}
	}
}t1,t2;
ll f[L][L],g[L][L];
int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cin>>n>>len;
	For(i,1,n){
		cin>>(s[i]+1);
		m[i]=strlen(s[i]+1);
		For(j,1,m[i]){
			rs[i][j]=s[i][m[i]+1-j];
		}
		t1.insert(i,s[i],pre[i]);
		t2.insert(i,rs[i],suf[i]);
	}
	t1.dfs(0,trans1);
	t2.dfs(0,trans2);
	For(i,1,n){
		g[0][pre[i][m[i]]]++;
	}
	For(i,0,len/2){
		For(j,0,t1.tot){
			if(!g[i][j]) continue;
			debug("g %d %d=%lld\n",i,j,g[i][j]);
			for(int k:trans1[j]){
				if(m[k]<=t1.dep[j]){
					(g[i+m[k]][t1.anc[j][m[k]]]+=g[i][j])%=Mod;
				}else{
					(f[i+t1.dep[j]][suf[k][m[k]-t1.dep[j]]]+=g[i][j])%=Mod;
				}
			}
		}
		For(j,0,t2.tot){
			if(!f[i][j]) continue;
			debug("f %d %d=%lld\n",i,j,f[i][j]);
			for(int k:trans2[j]){
				if(m[k]<=t2.dep[j]){
					(f[i+m[k]][t2.anc[j][m[k]]]+=f[i][j])%=Mod;
				}else{
					(g[i+t2.dep[j]][pre[k][m[k]-t2.dep[j]]]+=f[i][j])%=Mod;
				}
			}
		}
	}
	ll ans=0;
	For(i,0,len/2){
		For(j,0,t1.tot){
			if(i*2+t1.dep[j]==len&&t1.palin[j]){
				(ans+=g[i][j])%=Mod;
			}
		}
		For(j,0,t2.tot){
			if(i*2+t2.dep[j]==len&&t2.palin[j]){
				(ans+=f[i][j])%=Mod;
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4184kb

input:

7 9
cats
eel
eve
evil
lee
olive
stack

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 1ms
memory: 4004kb

input:

2 2
a
aa

output:

2

result:

ok single line: '2'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 4176kb

input:

6 12
aa
aab
no
on
pets
step

output:

16

result:

wrong answer 1st lines differ - expected: '43', found: '16'