/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 580.0 KiB
#2 Accepted 2ms 616.0 KiB
#3 Accepted 2ms 580.0 KiB
#4 Accepted 2ms 444.0 KiB
#5 Accepted 2ms 1.039 MiB
#6 Accepted 7ms 4.258 MiB
#7 Accepted 16ms 12.059 MiB
#8 Accepted 16ms 12.02 MiB
#9 Accepted 60ms 57.977 MiB
#10 Accepted 176ms 191.863 MiB
#11 Accepted 173ms 191.871 MiB
#12 Accepted 176ms 191.801 MiB
#13 Accepted 176ms 191.742 MiB
#14 Accepted 178ms 191.781 MiB
#15 Accepted 175ms 191.762 MiB
#16 Accepted 176ms 191.883 MiB
#17 Accepted 175ms 191.738 MiB
#18 Accepted 2ms 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-11-11 02:50:11
Judged By
Score
100
Total Time
178ms
Peak Memory
191.883 MiB