/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 1ms 532.0 KiB
#3 Wrong Answer 1ms 580.0 KiB
#4 Wrong Answer 1ms 532.0 KiB
#5 Wrong Answer 2ms 828.0 KiB
#6 Wrong Answer 5ms 2.73 MiB
#7 Wrong Answer 8ms 5.598 MiB
#8 Wrong Answer 8ms 5.52 MiB
#9 Accepted 21ms 16.324 MiB
#10 Accepted 37ms 32.27 MiB
#11 Wrong Answer 37ms 32.281 MiB
#12 Accepted 38ms 32.414 MiB
#13 Accepted 36ms 32.312 MiB
#14 Wrong Answer 37ms 32.227 MiB
#15 Wrong Answer 37ms 32.242 MiB
#16 Accepted 36ms 32.441 MiB
#17 Accepted 37ms 32.379 MiB
#18 Wrong Answer 2ms 532.0 KiB

Code

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds; 
using namespace std;
 
typedef pair<long long,long long> PLL;
typedef long long LL;
 
#define all(v) v.begin(),v.end()
#define faster {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>    

const LL mod = 1e9 + 7;
const int N = 5000 + 10;
const LL inf = 1e9;

int get(char a, char b, char c){
    int ret = 0;
    ret += ('a' - a + 26) % 26;
    ret += ('b' - b + 26) % 26;
    ret += ('c' - c + 26) % 26;
    return ret;
}

int dp[N][N / 3];

void solve(int test){
    int n, k; cin>>n>>k; k = min(k, n * 26);
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n / 3; j++){
            dp[i][j] = inf;
        }
    }
    dp[0][0] = 0;
    char s[n + 1];
    for(int i = 1; i <= n; i++) cin>>s[i];

    for(int i = 3; i <= n; i++){
        int cost = get(s[i - 2], s[i - 1], s[i]);
        for(int j = 0; j <= n / 3; j++){
            dp[i][j] = min({dp[i][j], dp[i - 1][j], dp[i - 3][j - 1] + cost});
        }
    }
    int ans = 0;
    for(int i = 0; i <= n / 3; i++){
        if(dp[n][i] <= k) ans = i;
    }
    cout<<ans<<'\n';
}

signed main(){
    faster
    int t = 1; 
    cin>>t;
    for(int i = 1; i <= t; i++){
        solve(i);
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1100 Substring ABC
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 20:36:54
Judged At
2024-10-03 20:36:54
Judged By
Score
34
Total Time
38ms
Peak Memory
32.441 MiB