Logo Wy Online Judge

WyOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574#112. 【0621 模拟赛】7KrokodsAme_wiki10030ms3400kbC++14974b2025-06-21 14:31:352025-06-21 23:48:31

answer

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"

const int N=1e6+5,M=3005,inf=1e18;

int cl(int x){ return x*x; }

int n,m,maxx=-inf;
int t[500],k[500];
string s;

int check(){
	t[(int)'k']=0; t[(int)'o']=0; t[(int)'r']=0; t[(int)'d']=0;
	for(int i=n+1;i<=n+m;i++) t[s[i]]++;
	t[(int)'k']+=k[(int)'k']; t[(int)'o']+=k[(int)'o']; t[(int)'r']+=k[(int)'r']; t[(int)'d']+=k[(int)'d'];
	int ans=0;
	ans+=cl(t[(int)'k'])+cl(t[(int)'d'])+cl(t[(int)'r'])+cl(t[(int)'o']);
	ans+=min(min(t[(int)'k']/2,t[(int)'o']/2),min(t[(int)'r'],t[(int)'d']))*7;
	return ans;
}

void dfs(int x){
	if(x>=n+m+1){
		maxx=max(maxx,check());
		return ;
	}
	s[x]='k';
	dfs(x+1);
	s[x]='o';
	dfs(x+1);
	s[x]='r';
	dfs(x+1);
	s[x]='d';
	dfs(x+1);
	s[x]=' '; 
	return ;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n>>m>>s;
	s=" "+s;
	for(int i=1;i<=n;i++) k[(int)s[i]]++;
	dfs(n+1);
	cout<<maxx;
	return 0;
}

详细

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

Subtask #1:

score: 17
Accepted

Test #1:

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

input:

56 0
kkkkkkkkkkoooooooooorrrrrdddddkkkkkkkkkkooooooooookkkkoo

output:

1145

result:

ok "1145"

Test #2:

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

input:

4 0
dkor

output:

4

result:

ok "4"

Test #3:

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

input:

11 0
krokodkroko

output:

44

result:

ok "44"

Test #4:

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

input:

10 0
kkkkkkkkkk

output:

100

result:

ok "100"

Test #5:

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

input:

100 0
krokodkrodkrokodkrodkrokodkrodkrokodkrodkrokodkrodkrokodkrodkrokodkrodkrokodkrodkrokodkrodkrok...

output:

2705

result:

ok "2705"

Subtask #2:

score: 26
Accepted

Test #6:

score: 26
Accepted
time: 1ms
memory: 3352kb

input:

8 1
kodrrrrr

output:

39

result:

ok "39"

Test #7:

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

input:

5 1
kroko

output:

17

result:

ok "17"

Test #8:

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

input:

11 1
krokodkroko

output:

54

result:

ok "54"

Test #9:

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

input:

87 1
kkkokokokokdokdokodkodkdokdokdokdodkodkokokdodkorkrrrrrrrrrrrrrrrrrrrrdkokokokdrokrodkk

output:

2099

result:

ok "2099"

Subtask #3:

score: 7
Accepted

Test #10:

score: 7
Accepted
time: 1ms
memory: 3392kb

input:

5 3
dodor

output:

30

result:

ok "30"

Test #11:

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

input:

3 3
kro

output:

18

result:

ok "18"

Test #12:

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

input:

2 4
rd

output:

26

result:

ok "26"

Test #13:

score: 0
Accepted
time: 21ms
memory: 3360kb

input:

100 10
krokokdokorkokodkokrokokdorkokokdkdkkdkdrrrrddrkdokodkrokdorkdokdrokrdordkordkdrokdrokdrokdro...

output:

3415

result:

ok "3415"