/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 536.0 KiB
#3 Accepted 2ms 588.0 KiB
#4 Accepted 2ms 764.0 KiB
#5 Accepted 2ms 1.051 MiB
#6 Accepted 8ms 4.27 MiB
#7 Accepted 16ms 12.168 MiB
#8 Accepted 16ms 12.168 MiB
#9 Accepted 58ms 58.199 MiB
#10 Accepted 171ms 191.738 MiB
#11 Accepted 170ms 191.793 MiB
#12 Accepted 173ms 191.699 MiB
#13 Accepted 174ms 191.805 MiB
#14 Accepted 175ms 191.699 MiB
#15 Accepted 173ms 191.781 MiB
#16 Accepted 174ms 191.684 MiB
#17 Accepted 176ms 191.836 MiB
#18 Accepted 2ms 580.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-12-17 11:36:11
Judged By
Score
100
Total Time
176ms
Peak Memory
191.836 MiB