/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 764.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 2ms 532.0 KiB
#4 Accepted 2ms 524.0 KiB
#5 Accepted 2ms 1.039 MiB
#6 Accepted 7ms 4.336 MiB
#7 Accepted 15ms 12.066 MiB
#8 Accepted 15ms 12.02 MiB
#9 Accepted 57ms 58.059 MiB
#10 Accepted 164ms 191.707 MiB
#11 Accepted 183ms 191.793 MiB
#12 Accepted 165ms 191.77 MiB
#13 Accepted 179ms 191.715 MiB
#14 Accepted 177ms 191.812 MiB
#15 Accepted 165ms 191.77 MiB
#16 Accepted 175ms 191.73 MiB
#17 Accepted 169ms 191.715 MiB
#18 Accepted 3ms 532.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int dp[5005][5005];
char A[5005];

int cst(char x, char y){
	if(x <= y)return y - x;
	else return y - x + 26;
}

void solve(){
	int n, k; cin >> n >> k;
	for(int i = 1; i <= n; i++)cin >> A[i];
	for(int i = 0; i <= 2; i++)for(int j = 1; j <= n; j++)dp[i][j] = 1e18;
	for(int i = 3; i <= n; i++){
		for(int j = 1; j <= n; j++){
			dp[i][j] = min(dp[i - 1][j], dp[i - 3][j - 1] + cst(A[i - 2], 'a') + cst(A[i - 1], 'b') + cst(A[i], 'c'));
		}
	}
	for(int i = n; i >= 0; i--){
		if(dp[n][i] <= k){
			cout << i << '\n';
			return;
		}
	}
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Information

Submit By
Type
Submission
Problem
P1100 Substring ABC
Contest
Brain Booster #6
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 15:44:58
Judged At
2024-10-03 15:44:58
Judged By
Score
100
Total Time
183ms
Peak Memory
191.812 MiB