QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#352386 | #7994. 勿蹖宠物 | Graygoo | RE | 7ms | 10136kb | C++14 | 2.7kb | 2024-03-13 10:44:27 | 2024-03-13 10:44:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int tot1=0,tot2=0;
pair<int,int> d1[1005];
map<int,int> mp1[1005];
pair<int,int> d2[1005];
map<int,int> mp2[1005];
string s[1005];
#define ull unsigned long long
ull pw[1005];
vector<ull> hsh1[1005];
vector<ull> hsh2[1005];
int f[1005][1005];
bool ok1[1005][1005];
int g[1005][1005];
bool ok2[1005][1005];
int n,l;
ull get1(int id,int l,int r){
if(l>r)return 0;
return hsh1[id][r]-(l==0?0:hsh1[id][l-1])*pw[r-l+1];
}
ull get2(int id,int l,int r){
if(l>r)return 0;
return hsh2[id][l]-(r==(int)s[id].size()-1?0:hsh2[id][r+1])*pw[r-l+1];
}
int dp1(int L,int sta);
int dp2(int L,int sta);
int dp1(int L,int sta){
if(ok1[L][sta])return f[L][sta];
ok1[L][sta]=1;
int id=d1[sta].first;
int len=d1[sta].second;
if((int)s[id].size()-len>L)return f[L][sta]=0;
if((int)s[id].size()-len==L)return f[L][sta]=(get1(id,len,(int)s[id].size()-1)==get2(id,len,(int)s[id].size()-1)?1:0);
int res=s[id].size()-len;
for(int i=1;i<=n;i++){
if(res<(int)s[i].size()){
if(get1(id,len,(int)s[id].size()-1)==get2(i,(int)s[i].size()-res,(int)s[i].size()-1))f[L][sta]=(f[L][sta]+dp2(L-2*res,mp2[i][(int)s[i].size()-res-1]))%mod;
}else{
if(get1(id,len,len+(int)s[i].size()-1)==get2(i,0,(int)s[i].size()-1))f[L][sta]=(f[L][sta]+dp1(L-2*(int)s[i].size(),mp1[id][len+(int)s[i].size()]))%mod;
}
}
return f[L][sta];
}
int dp2(int L,int sta){
if(ok2[L][sta])return g[L][sta];
ok2[L][sta]=1;
int id=d2[sta].first;
int len=d2[sta].second;
if(len+1>L)return g[L][sta]=0;
if(len+1==L)return g[L][sta]=(get1(id,0,len)==get2(id,0,len)?1:0);
int res=len+1;
for(int i=1;i<=n;i++){
if(res<(int)s[i].size()){
if(get1(id,0,len)==get2(i,0,res-1))g[L][sta]=(g[L][sta]+dp1(L-2*res,mp1[i][res]))%mod;
}else{
if(get1(id,len-(int)s[i].size()+1,len)==get2(i,0,(int)s[i].size()-1))g[L][sta]=(g[L][sta]+dp2(L-2*(int)s[i].size(),mp2[id][len-(int)s[i].size()]))%mod;
}
}
return g[L][sta];
}
signed main(){
cin>>n>>l;
pw[0]=1;
for(int i=1;i<=1000;i++)pw[i]=pw[i-1]*137;
for(int i=1;i<=n;i++){
cin>>s[i];
hsh1[i].resize(s[i].size());
hsh2[i].resize(s[i].size());
for(int j=0;j<(int)s[i].size();j++){
tot1++;d1[tot1]={i,j};mp1[i][j]=tot1;
hsh1[i][j]=(j==0?0:hsh1[i][j-1])*137+s[i][j];
}
tot1++;d1[tot1]={i,(int)s[i].size()};mp1[i][(int)s[i].size()]=tot1;
for(int j=(int)s[i].size()-1;j>=0;j--){
tot2++;d2[tot2]={i,j};mp2[i][j]=tot2;
hsh2[i][j]=(j==(int)s[i].size()-1?0:hsh2[i][j+1])*137+s[i][j];
}
tot2++;d2[tot2]={i,-1};mp2[i][-1]=tot2;
}
cout<<dp1(l,mp1[1][(int)s[1].size()])<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3788kb
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: 3812kb
input:
2 2 a aa
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3808kb
input:
6 12 aa aab no on pets step
output:
43
result:
ok single line: '43'
Test #4:
score: 0
Accepted
time: 7ms
memory: 10136kb
input:
26 1000 a b c d e f g h i j k l m n o p q r s t u v w x y z
output:
710955506
result:
ok single line: '710955506'
Test #5:
score: -100
Runtime Error
input:
33 18 zrkodfkhhkfdokrzo ytcbwrgyygrwbcty makgiybggbyigkamc aptmvovgccgvovmtpa yydxdzhhhhzdxdyy iadqfexoxacojythvk iagcfiwlaalwifcgai rtfzhddzzddhzftrm vkreigbdyxfiuvyqid mbcgnvrvvrvngcbmc lywbtspuyyupstbwyl bmjxalsyyslaxjmb jrbminaooanimbrj wwrajerkkrejarww grocaiqccqiacorg efvibgurrugbivfec ilyzrft...