比赛 2026.9.12 评测结果 TTEEEEEEEE
题目名称 字符串游戏 最终得分 0
用户昵称 xuyuqing 运行时间 2.304 s
代码语言 C++ 内存使用 3.79 MiB
提交时间 2026-09-12 11:06:03
显示代码纯文本

#include <cstdio>
#include <iostream>

using namespace std;

const int N = 11;

string str;
int n;
char ch[N];
long long res;

void solve (int dep) {
	if (dep > n) {
		long long ans = 0;
		string t = "";
		for (int i = dep - 1; i > 0; i--) {
			t = ch[i] + t;
			
			int j = 0;
			while (str[j] == t[j] && j < t.size()) {
				j++;
			}
			
			ans += j;
		}
		res = max (res, ans);
		return;
	}
	for (char c = 'a'; c <= 'z'; c++) {
		ch[dep] = c;
		solve (dep + 1);
	}
}

int main () {
	
	freopen ("string.in", "r", stdin);
	freopen ("string.out", "w", stdout);
	
	cin >> str >> n;
	solve (1);
	
	cout << res << endl;
	
	return 0;
}