QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#352389#7994. 勿蹖宠物GraygooRE 7ms12252kbC++142.7kb2024-03-13 10:45:562024-03-13 10:45:58

Judging History

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

  • [2024-03-13 10:45:58]
  • 评测
  • 测评结果:RE
  • 用时:7ms
  • 内存:12252kb
  • [2024-03-13 10:45:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int tot1=0,tot2=0;
pair<int,int> d1[2005];
map<int,int> mp1[2005];
pair<int,int> d2[2005];
map<int,int> mp2[2005];
string s[2005];
#define ull unsigned long long
ull pw[2005];
vector<ull> hsh1[2005];
vector<ull> hsh2[2005];
int f[2005][2005];
bool ok1[2005][2005];
int g[2005][2005];
bool ok2[2005][2005];
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<=2000;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;
}

詳細信息

Test #1:

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

input:

7 9
cats
eel
eve
evil
lee
olive
stack

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 0ms
memory: 4040kb

input:

2 2
a
aa

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 0ms
memory: 4020kb

input:

6 12
aa
aab
no
on
pets
step

output:

43

result:

ok single line: '43'

Test #4:

score: 0
Accepted
time: 7ms
memory: 12252kb

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...

output:


result: