Logo Wy Online Judge

WyOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#585#112. 【0621 模拟赛】7Krokodszhangyining235710010ms3444kbC++14808b2025-06-21 14:37:232025-06-21 23:48:49

answer

#include<iostream>
#include<cstring>
using namespace std;
#define int long long
int maxn=0;
int dfs(int n,int a,int b,int c,int d){
	if(n==0){
		int t=a*a+b*b+c*c+d*d+7*min(a/2,min(b/2,min(c,d)));
		maxn=max(maxn,t);
		return t;
	}
	int t=dfs(n-1,a+1,b,c,d);
	t=max(t,dfs(n-1,a,b+1,c,d));
	t=max(t,dfs(n-1,a,b,c+1,d));
	t=max(t,dfs(n-1,a,b,c,d+1));
	return t;
}
using namespace std;
char s[100001];
int a,b,c,d,t,g;
signed main(){
	cin>>t>>g; 
	cin>>s;
	for(int i=0;i<t;i++){
		if(s[i]=='d'){
			c++;
		}
		if(s[i]=='k'){
			a++;
		}
		if(s[i]=='r'){
			d++;
		}
		if(s[i]=='o'){
			b++;
		}
	}
	cout<<dfs(g,a,b,c,d);
	return 0;
} 
//6 4 2 3
//36
//16
//4
//9





















//(x1+a)^2+(x2+b)^2+(x3+c)^2+(x4+d)^2+min((x1+a)/2,(x2+b)/2,)

Details

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 17
Accepted

Test #1:

score: 17
Accepted
time: 1ms
memory: 3384kb

input:

56 0
kkkkkkkkkkoooooooooorrrrrdddddkkkkkkkkkkooooooooookkkkoo

output:

1145

result:

ok "1145"

Test #2:

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

input:

4 0
dkor

output:

4

result:

ok "4"

Test #3:

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

input:

11 0
krokodkroko

output:

44

result:

ok "44"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3300kb

input:

10 0
kkkkkkkkkk

output:

100

result:

ok "100"

Test #5:

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

input:

100 0
krokodkrodkrokodkrodkrokodkrodkrokodkrodkrokodkrodkrokodkrodkrokodkrodkrokodkrodkrokodkrodkrok...

output:

2705

result:

ok "2705"

Subtask #2:

score: 26
Accepted

Test #6:

score: 26
Accepted
time: 0ms
memory: 3112kb

input:

8 1
kodrrrrr

output:

39

result:

ok "39"

Test #7:

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

input:

5 1
kroko

output:

17

result:

ok "17"

Test #8:

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

input:

11 1
krokodkroko

output:

54

result:

ok "54"

Test #9:

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

input:

87 1
kkkokokokokdokdokodkodkdokdokdokdodkodkokokdodkorkrrrrrrrrrrrrrrrrrrrrdkokokokdrokrodkk

output:

2099

result:

ok "2099"

Subtask #3:

score: 7
Accepted

Test #10:

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

input:

5 3
dodor

output:

30

result:

ok "30"

Test #11:

score: 0
Accepted
time: 1ms
memory: 3380kb

input:

3 3
kro

output:

18

result:

ok "18"

Test #12:

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

input:

2 4
rd

output:

26

result:

ok "26"

Test #13:

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

input:

100 10
krokokdokorkokodkokrokokdorkokokdkdkkdkdrrrrddrkdokodkrokdorkdokdrokrdordkordkdrokdrokdrokdro...

output:

3415

result:

ok "3415"