QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#642982#6366. Messageyzc358230151WA 113ms101648kbC++142.7kb2024-10-15 17:28:112024-10-15 17:28:18

Judging History

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

  • [2024-10-15 17:28:18]
  • 评测
  • 测评结果:WA
  • 用时:113ms
  • 内存:101648kb
  • [2024-10-15 17:28:11]
  • 提交

answer

/*
	(E)原神https://qoj.ac/download.php?type=attachments&id=1213&r=0
	https://qoj.ac/contest/1213/problem/6366
*/
#include<bits/stdc++.h>
using namespace std;
#define gc getchar
#define pc putchar
#define mkp make_pair
#define pb push_back
typedef long long ll;
char s[200010],t[200010];
int ls,lt;
int w[200010];
bool hd[200010];//段首标记
ll smw[200010];
ll dp[60][200010];int dpcnt;
int fst[26],lst[26];
int L=1,R;
int occ[200010],occcnt;
namespace kmp{
	int nxt[200010];
	char *r;
	void kmp(){
		int le=R-L+1;
		occcnt=0,
		r=t+L-1;
		for(int i=1;i<=le;++i)
			nxt[i]=0;
		nxt[0]=-1,
		nxt[1]=0;
		int j=0;
		for(int i=2;i<=le;++i){
			while((~j)&&r[j+1]!=r[i])
				j=nxt[j];
			nxt[i]=++j;
		}
		j=0;
		for(int i=1;i<=ls;++i){
			while((~j)&&r[j+1]!=s[i])
				j=nxt[j];
			++j;
			if(j==le)
				occ[++occcnt]=i-le+1,
				j=nxt[j];
		}
	}
}
void mkdp(){
	++dpcnt,kmp::kmp();
	int len=R-L+1;
	// printf("doing #%d dp,with area [%d,%d]\n",
	// dpcnt,L,R);
	// printf("occurs:\n");
	// for(int i=1;i<=occcnt;++i)
	// 	printf("[%d,%d],",occ[i],occ[i]+len-1);
	// printf("\n");
	ll mxfr=-1;int pt=1;
	for(int i=1;i<=occcnt;++i){
		// for(;pt<occ[i];++pt)
		// if(L<=fst[s[pt]-'a']||L>lst[s[pt]-'a'])
		// 	printf("maxxed mxfr at pt=%d\n",pt),
		// 	mxfr=max(mxfr,dp[dpcnt-1][pt]);
		// else
		// 	printf("banned mxfr at pt=%d\n",pt),
		// 	mxfr=-1;
		for(;pt<occ[i];++pt)
		if(L<=fst[s[pt]-'a']||L>lst[s[pt]-'a'])
			// printf("maxxed mxfr at pt=%d\n",pt),
			mxfr=max(mxfr,dp[dpcnt-1][pt-1]);
		else
			// printf("banned mxfr at pt=%d\n",pt),
			mxfr=-1;
		mxfr=max(mxfr,dp[dpcnt-1][occ[i]-1]);
		if(~mxfr)
			dp[dpcnt][occ[i]+len-1]=mxfr
			+smw[occ[i]+len-1]-smw[occ[i]-1];
	}
	for(int i=2;i<=ls;++i)
	if(R+1<=fst[s[i]-'a']||R+1>lst[s[i]-'a'])
		dp[dpcnt][i]=
		max(dp[dpcnt][i],dp[dpcnt][i-1]);
}
signed main(){
	scanf("%s%s",s+1,t+1),
	ls=strlen(s+1),
	lt=strlen(t+1);
	for(int i=1;i<=ls;++i)
		scanf("%d",&w[i]),
		smw[i]=smw[i-1]+w[i];
	for(int i=1;i<=lt;++i){
		if(!fst[t[i]-'a'])
			fst[t[i]-'a']=i;
		lst[t[i]-'a']=i;
	}
	memset(dp,~0x3f,sizeof(dp));
	for(int i=0;i<26;++i)
		// printf("'%c' is [%d,%d]",
		// i+'a',fst[i],lst[i]),
		hd[fst[i]]=hd[lst[i]+1]=1;
	hd[lt+1]=1,dp[0][0]=0;
	for(R=1;R<=lt;++R)
	if(hd[R+1])
		mkdp(),
		L=R+1;
	if(dp[dpcnt][ls]>=0)
		printf("%lld",smw[ls]-dp[dpcnt][ls]);
	else
		fputs("You better start from scratch man...\n",stdout);
		// fputs("-1\n",stdout);
		//You better start from scratch man...
	return 0;
}
/*
必须连续匹配的串。
具体地,新出现的字符在其前划分,其作为段首;
最后的字符在其后划分,其作为段尾。
注意某些字符不能跳过。
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 97660kb

input:

ababccb
abc
7 2 2 4 3 2 1

output:

7

result:

ok single line: '7'

Test #2:

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

input:

babab
baab
2 1 3 2 4

output:

You better start from scratch man...

result:

ok single line: 'You better start from scratch man...'

Test #3:

score: 0
Accepted
time: 30ms
memory: 101648kb

input:

bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...

output:

You better start from scratch man...

result:

ok single line: 'You better start from scratch man...'

Test #4:

score: 0
Accepted
time: 35ms
memory: 101340kb

input:

bdabcfbdfcffebebcabbadacbbaeeaffbdedeedfabefdfdbddcecdaaddafdfbbdceccedebcecdfbcfbaafcefeecffdabfaacbeeecfeffaaafaefdcdaaeaeecfafcdadbfbccbdecacfeabdbfcacafebdcfbfbebacbffaecbfbcedccabbdecabaebbbdbcfbaeadfcadfadfaebaddbebfcbefdabdcefbbdaaaabcefedabcabcafedcfadedfdcbbccbffdcfdfcfcdfcfbbdabdbbeecafecc...

output:

You better start from scratch man...

result:

ok single line: 'You better start from scratch man...'

Test #5:

score: 0
Accepted
time: 113ms
memory: 101112kb

input:

soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...

output:

You better start from scratch man...

result:

ok single line: 'You better start from scratch man...'

Test #6:

score: 0
Accepted
time: 23ms
memory: 101516kb

input:

bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 72ms
memory: 101148kb

input:

hdhlkjabgckjkagfgkigfebfjmdabahajicgkfmblafmfgkiimkjlciiaegbkbkicgklhbhfmclghkleghmckbjliiicmmecldieghfdeghgechcjahdfebkhdigbkklcclieccijaemchbmfcggcjmgbdjhcbacleajjjledkfdjebgdmgahkjigjjighlbedbellabffeeckfbghcblmmgjijdehmcameeledejfijfmfcfkjdjklfldhmkabblcbgebhibkmihelehjccgggjhhbjehfidfmmjdgmmjbf...

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 110ms
memory: 101368kb

input:

soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...

output:

0

result:

ok single line: '0'

Test #9:

score: 0
Accepted
time: 8ms
memory: 99612kb

input:

aaaaaaaaaa
a
670064684 12247274 885150692 755303894 373857482 772871474 451986656 733926307 275101324 732261937

output:

4777621032

result:

ok single line: '4777621032'

Test #10:

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

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaa
807194254 763061330 636628022 447638039 310117480 873320507 134259988 666480259 747042520 231541618 643931761 30317274 158530414 253502390 229547045 438239031 709645547 367432988 755781758 67144518 360508870 862615691 635226301 863755466 104979114 4...

output:

5115514604

result:

ok single line: '5115514604'

Test #11:

score: 0
Accepted
time: 4ms
memory: 99540kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaa
768295104 305748099 281563038 518303412 678146171 512832379 509999474 360793781 979858190 884904151 886121576 776530718 147119220 985829130 553994391 500082956 167860347 562080893 520228135 790526162 270707017 179265550 913606870 245853815 83...

output:

21140461276

result:

ok single line: '21140461276'

Test #12:

score: 0
Accepted
time: 3ms
memory: 99680kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
684483834 637018127 270602950 736485564 883414052 758886073 266638494 906099301 851227039 479339928 603217972 474167559 537788182 324629484 719852776 8079...

output:

27302362948

result:

ok single line: '27302362948'

Test #13:

score: 0
Accepted
time: 4ms
memory: 97648kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

131859070652

result:

ok single line: '131859070652'

Test #14:

score: 0
Accepted
time: 8ms
memory: 97612kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

781196173176

result:

ok single line: '781196173176'

Test #15:

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

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

4343956108320

result:

ok single line: '4343956108320'

Test #16:

score: 0
Accepted
time: 8ms
memory: 99840kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

18494567762260

result:

ok single line: '18494567762260'

Test #17:

score: 0
Accepted
time: 12ms
memory: 100768kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

32209183658799

result:

ok single line: '32209183658799'

Test #18:

score: 0
Accepted
time: 15ms
memory: 100864kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

54681136007004

result:

ok single line: '54681136007004'

Test #19:

score: 0
Accepted
time: 20ms
memory: 101332kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

29370598770431

result:

ok single line: '29370598770431'

Test #20:

score: -100
Wrong Answer
time: 4ms
memory: 99756kb

input:

aaaabababb
bb
476848657 19478030 860633182 479517749 926931997 990353030 811177212 276072809 44418816 639422667

output:

4841012666

result:

wrong answer 1st lines differ - expected: '3786744940', found: '4841012666'