/ SeriousOJ /

Record Detail

Memory Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 2ms 540.0 KiB
#3 Accepted 2ms 576.0 KiB
#4 Accepted 4ms 584.0 KiB
#5 Accepted 20ms 1.551 MiB
#6 Accepted 50ms 25.582 MiB
#7 Accepted 59ms 42.926 MiB
#8 Accepted 80ms 43.121 MiB
#9 Accepted 199ms 116.559 MiB
#10 Accepted 78ms 56.852 MiB
#11 Accepted 207ms 169.363 MiB
#12 Memory Exceeded ≥190ms ≥256.016 MiB
#13 Accepted 153ms 120.609 MiB
#14 Accepted 143ms 114.711 MiB
#15 Memory Exceeded ≥193ms ≥256.016 MiB
#16 Memory Exceeded ≥189ms ≥256.016 MiB
#17 Memory Exceeded ≥188ms ≥256.016 MiB
#18 Accepted 3ms 336.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 = 2e5 + 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;
}

void solve(int test){
    int n, k; cin>>n>>k; k = min(k, n * 26);
    char s[n + 1];
    for(int i = 1; i <= n; i++) cin>>s[i];
    int dp[n + 1][k + 10] = {};
    for(int i = 3; i <= n; i++){
        int cost = get(s[i - 2], s[i - 1], s[i]);
        for(int j = 0; j <= k; j++){
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
            if(j + cost > k) continue; 
            int &cur = dp[i][j + cost];
            cur = max(cur, dp[i - 3][j] + 1);
        }
    }
    int ans = 0;
    for(int i = 0; i <= k; i++)
        ans = max(ans, dp[n][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
Contest
Brain Booster #6
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 17:59:47
Judged At
2024-10-03 17:59:47
Judged By
Score
87
Total Time
≥207ms
Peak Memory
≥256.016 MiB