QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#483758#7368. 抄写szcqwq100 ✓14ms38084kbC++141.4kb2024-07-19 12:01:312024-07-19 12:01:31

Judging History

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

  • [2024-07-19 12:01:31]
  • 评测
  • 测评结果:100
  • 用时:14ms
  • 内存:38084kb
  • [2024-07-19 12:01:31]
  • 提交

answer

//writer:Oier_szc

#include <bits/stdc++.h>
//#include <windows.h>
#define ED cerr<<endl;
#define TS cerr<<"I AK IOI"<<endl;
#define cr(x) cerr<<x<<endl;
#define cr2(x,y) cerr<<x<<" "<<y<<endl;
#define cr3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<endl;
#define cr4(x,y,z,w) cerr<<x<<" "<<y<<" "<<z<<" "<<w<<endl;
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
//#define ull unsigned long long
using namespace std;
const int N=1e6+5,mod=1e9+7;
const ll INF=1e16;
int n,c;
int v[30];
char _s[N],s[N<<1];
int p[N<<1],len=0;
ll dp[N<<1];
int q[N<<1],l=1,r=0;

void init() {
	s[++len]='$',s[++len]='#';
	for(int i=1;i<=n;++i) s[++len]=_s[i],s[++len]='#';
	s[++len]='^';
}

void manacher() {
	int mr=0,mid=0;
	for(int i=1;i<len;++i) {
		if(i<mr) p[i]=min(p[2*mid-i],mr-i);
		else p[i]=1;
		while(s[i+p[i]]==s[i-p[i]]) ++p[i];
		if(i+p[i]>mr) mr=i+p[i],mid=i;
	}
}


int main()
{
	scanf("%d%d",&n,&c);
	for(int i=0;i<26;++i) {
		scanf("%d",&v[i]);
	}
	scanf("%s",_s+1);
	init(),manacher();
	for(int i=1;i<=len;++i) dp[i]=INF;
	dp[1]=0;
	int fr;
	for(int i=3;i<=len-2;++i) {
		while(l<=r&&(q[l]+p[q[l]]-1<i||2*q[l]-i<3)) ++l;
		if(i&1) {
			dp[i]=dp[i-2]+v[s[i]-'a'];
			if(l<=r) {
				fr=q[l];
				if(!(fr&1)) --fr;
				dp[i]=min(dp[i],dp[fr]+c);
			}
		}
		q[++r]=i;
	}
	printf("%lld\n",dp[len-2]);
	return 0;
}

詳細信息

Test #1:

score: 10
Accepted
time: 1ms
memory: 8028kb

input:

10 920
316 915 331 834 181 122 238 511 910 632 652 717 369 468 866 140 89 183 83 376 257 670 127 643 983 105
xaaxrdtjqv

output:

4663

result:

ok single line: '4663'

Test #2:

score: 10
Accepted
time: 1ms
memory: 9976kb

input:

659 423
752 190 254 128 821 695 798 216 809 606 970 45 830 149 247 662 348 883 122 310 519 81 420 407 854 141
tttttttttttttttttttttttttttccccccccccqqqqqqqqqqdddddddddddbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssoooooooooooooooooooooo...

output:

39639

result:

ok single line: '39639'

Test #3:

score: 10
Accepted
time: 0ms
memory: 8076kb

input:

1000 82508
77548 11366 41959 92623 12754 24025 69335 82809 10717 2487 20842 21597 79490 55616 4586 81371 61068 60639 38689 99285 67058 4417 48118 92298 48938 46998
fswgxhmntgjmxddxuxddxmjgtnmhxgwuwgxhmntgjmxddxuxddxmjgtnmhxgwuwgxhmntgjmxddxuxddxmjgtnmhxgwuwgxhmntgjmxddxuxddxmjgtnmhxgwuwgxhmntgjmxddx...

output:

5152476

result:

ok single line: '5152476'

Test #4:

score: 10
Accepted
time: 1ms
memory: 9936kb

input:

1000 81447
73552 15604 67150 50813 61186 62462 95570 13768 1915 12710 9768 10234 73803 67198 83028 62207 7498 72453 18426 76800 20581 66504 49434 7136 9199 40151
jdxxltlxxdjtjdxxltuhsbscjqqgdoyodgqqjcsbshuyuhsbscjqqgdoyodgqqjcsbshuyuhsbscjqqgdoyodgqqjcsbshuyuhsbscjqqgdoyodgqqjcsbshuyuhsbscjqqgdoyodg...

output:

4700857

result:

ok single line: '4700857'

Test #5:

score: 10
Accepted
time: 0ms
memory: 11688kb

input:

97366 425
238 96 326 413 643 743 806 601 213 8 229 585 852 183 887 272 137 891 480 337 135 411 265 906 807 382
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

82531

result:

ok single line: '82531'

Test #6:

score: 10
Accepted
time: 3ms
memory: 13472kb

input:

100000 33379
12170 1675 69834 14368 91570 82932 66141 88159 4220 35820 24836 1083 77102 4471 78735 61628 53746 58134 40036 49369 65424 60061 79771 76791 91398 8101
imqqzaazqqmiimqqzaazqqmiimqqzakuochddhcoukkuochddhcoukkuochddhcoukkuochddhcoukkuochddhcoukkuochddhcoukkuochddhcoukkuochddhcoukkuochddhco...

output:

8203706

result:

ok single line: '8203706'

Test #7:

score: 10
Accepted
time: 3ms
memory: 15048kb

input:

100000 9107925
3181820 1305477 3152716 3739224 5572782 7916058 6479616 5154334 6622906 5541248 2719333 384761 3475969 4897963 6983868 175635 6509182 3008693 8373041 5777658 7480682 1658648 2725231 3311916 6180881 2740645
mjsgonduqaaqudnogsjmxiddixxiddixxiddixxiddixxiddixxiddixxiddixxiddixxiddixxiddi...

output:

933701481

result:

ok single line: '933701481'

Test #8:

score: 10
Accepted
time: 14ms
memory: 37600kb

input:

940823 71
102 70 3 282 34 642 912 683 628 633 870 57 395 952 427 275 323 655 720 960 557 114 417 354 557 554
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy...

output:

19337

result:

ok single line: '19337'

Test #9:

score: 10
Accepted
time: 8ms
memory: 37952kb

input:

1000000 80005
23657 44948 43486 12462 38795 28137 60947 38872 76125 27490 97511 91032 95028 17525 64016 68451 91721 63645 18338 55030 89004 15169 95322 26813 19323 44805
tccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttccttc...

output:

32904829

result:

ok single line: '32904829'

Test #10:

score: 10
Accepted
time: 12ms
memory: 38084kb

input:

1000000 743705502
203355312 642593104 49509407 833553504 721765697 645923593 987676530 855140950 875859311 522957598 441082466 49068898 921312225 548185354 505533262 26737495 674175585 995483029 131477261 936989048 613365908 712282356 798743656 807929778 320579711 517544929
vhhvvhhvvhhvvhhvvhhvvhhvv...

output:

317604809969

result:

ok single line: '317604809969'