QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#523427#2273. Suffixes may Contain PrefixesBreakPlusWA 4ms129468kbC++141.2kb2024-08-18 10:45:562024-08-18 10:45:56

Judging History

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

  • [2024-08-18 10:45:56]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:129468kb
  • [2024-08-18 10:45:56]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pb emplace_back
#define mkp make_pair
inline ll read(){ ll x; scanf("%lld",&x); return x; }
const ll mod = 998244353;
ll n,m,f[4005],jp[4005][26]; char s[4005];
ll dp[4005][4005],con[4005];
void solve(){
	scanf("%s",s+1); n=strlen(s+1);
	m=read(); con[1]=1;
//	memset(jp[1], -1, sizeof(jp[1]));
	for(ll i=0;i<=n;i++){
		if(i>1){
			f[i]=f[i-1];
			while(f[i] && s[f[i]+1] != s[i]) f[i]=f[f[i]];
			if(s[f[i]+1] == s[i]) f[i]++;
//			cout<<i<<" border "<<f[i]<<endl;
//			con[i]=con[f[i]]+1;
//			cout<<"at "<<con[i]<<endl;
		}
		for(ll j=0;j<3;j++){
			ll now=i;
			while(now && s[now+1] != j+'a') now=f[now];
			if(s[now+1] != j+'a') jp[i][j] = 0;
			else jp[i][j] = now+1;
			cout<<i<<","<<(char)(j+'a')<<" : "<<jp[i][j]<<endl;
		}
	}
	memset(dp, 0xb0, sizeof(dp)); dp[0][0]=0;
	for(ll i=0;i<m;i++){
		for(ll j=0;j<=n;j++){
			for(ll k=0;k<3;k++){
				dp[i+1][jp[j][k]] = max(dp[i+1][jp[j][k]], dp[i][j]+con[jp[j][k]]);
			}
		}
	}
	ll ans=-1e18;
	for(ll i=0;i<=n;i++){
		ans=max(ans, dp[m][i]);
	}
	printf("%lld\n", ans);
}

int main(){
	ll T=1; while(T--) solve();
}




Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 129468kb

input:

fsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfsfsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfsfsfffsfffssfsfffsfsf...

output:

0,a : 0
0,b : 0
0,c : 0
1,a : 0
1,b : 0
1,c : 0
2,a : 0
2,b : 0
2,c : 0
3,a : 0
3,b : 0
3,c : 0
4,a : 0
4,b : 0
4,c : 0
5,a : 0
5,b : 0
5,c : 0
6,a : 0
6,b : 0
6,c : 0
7,a : 0
7,b : 0
7,c : 0
8,a : 0
8,b : 0
8,c : 0
9,a : 0
9,b : 0
9,c : 0
10,a : 0
10,b : 0
10,c : 0
11,a : 0
11,b : 0
11,c : 0
12,a :...

result:

wrong answer 1st lines differ - expected: '852', found: '0,a : 0'