Logo Wy Online Judge

WyOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#599#112. 【0621 模拟赛】7KrokodsS0857710010ms5556kbC++141.0kb2025-06-21 14:47:492025-06-21 23:49:17

answer

#include<bits/stdc++.h>

#define int long long

using namespace std;

const int N=2e5+10;
const int Max=1e9+10;

int a[N];
string s;
int n,m;

int t[N],t1[N];
int maxx=0;
void dfs(int d,int rt){
	if(rt==0||d==5){
		int cnt=0;
		for(int i=1;i<=4;i++){
			cnt+=t[i]*t[i];
		}
		int minn=0x3f3f3f3f;
		for(int i=1;i<=4;i++){
			if(i==1||i==3){
				minn=min(minn,t[i]/2);
			}
			else minn=min(minn,t[i]);
		}
		cnt+=minn*7;
		maxx=max(maxx,cnt);
		return ;
	}
	for(int i=0;i<=rt;i++){
		t[d]+=i;
		dfs(d+1,rt-i);
		t[d]-=i;
	}
	
}

signed main(){
	cin>>n>>m;
	cin>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='k') t[1]++;
		if(s[i]=='r') t[2]++;
		if(s[i]=='o') t[3]++;
		if(s[i]=='d') t[4]++;
	}
	if(m==0){
		int cnt=0;
		for(int i=1;i<=4;i++){
			cnt+=t[i]*t[i];
		}
		int minn=0x3f3f3f3f;
		for(int i=1;i<=4;i++){
			if(i==1||i==3){
				minn=min(minn,t[i]/2);
			}
			else minn=min(minn,t[i]);
		}
		cnt+=minn*7;
		cout<<cnt;
		return 0;
	}
	for(int i=1;i<=4;i++) t1[i]=t[i];
	dfs(1,m);
	cout<<maxx;
	return 0;
} 

详细

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

Subtask #1:

score: 17
Accepted

Test #1:

score: 17
Accepted
time: 0ms
memory: 5508kb

input:

56 0
kkkkkkkkkkoooooooooorrrrrdddddkkkkkkkkkkooooooooookkkkoo

output:

1145

result:

ok "1145"

Test #2:

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

input:

4 0
dkor

output:

4

result:

ok "4"

Test #3:

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

input:

11 0
krokodkroko

output:

44

result:

ok "44"

Test #4:

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

input:

10 0
kkkkkkkkkk

output:

100

result:

ok "100"

Test #5:

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

input:

100 0
krokodkrodkrokodkrodkrokodkrodkrokodkrodkrokodkrodkrokodkrodkrokodkrodkrokodkrodkrokodkrodkrok...

output:

2705

result:

ok "2705"

Subtask #2:

score: 26
Accepted

Test #6:

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

input:

8 1
kodrrrrr

output:

39

result:

ok "39"

Test #7:

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

input:

5 1
kroko

output:

17

result:

ok "17"

Test #8:

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

input:

11 1
krokodkroko

output:

54

result:

ok "54"

Test #9:

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

input:

87 1
kkkokokokokdokdokodkodkdokdokdokdodkodkokokdodkorkrrrrrrrrrrrrrrrrrrrrdkokokokdrokrodkk

output:

2099

result:

ok "2099"

Subtask #3:

score: 7
Accepted

Test #10:

score: 7
Accepted
time: 2ms
memory: 5444kb

input:

5 3
dodor

output:

30

result:

ok "30"

Test #11:

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

input:

3 3
kro

output:

18

result:

ok "18"

Test #12:

score: 0
Accepted
time: 2ms
memory: 5532kb

input:

2 4
rd

output:

26

result:

ok "26"

Test #13:

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

input:

100 10
krokokdokorkokodkokrokokdorkokokdkdkkdkdrrrrddrkdokodkrokdorkdokdrokrdordkordkdrokdrokdrokdro...

output:

3415

result:

ok "3415"