/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Accepted 6ms 580.0 KiB
#3 Accepted 71ms 532.0 KiB
#4 Accepted 162ms 644.0 KiB
#5 Accepted 840ms 83.32 MiB
#6 Accepted 872ms 83.227 MiB
#7 Accepted 822ms 41.938 MiB
#8 Accepted 433ms 8.832 MiB
#9 Accepted 127ms 592.0 KiB
#10 Accepted 81ms 532.0 KiB
#11 Accepted 848ms 83.312 MiB
#12 Accepted 850ms 83.32 MiB
#13 Accepted 867ms 83.27 MiB

Code

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

// #define int long long
#define endl "\n"
#define F first
#define S second
#define pii pair<int, int>
#define sz(x) (int) (x.size())


// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// template<typename T> using o_set = tree<T, null_type, std::less<T>, 
// rb_tree_tag, tree_order_statistics_node_update>;

string tmp = "aeiou";


const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const int INF = 1e9 + 10;
int f(char ch) {
    if(ch == 'a') return 0;
    if(ch == 'e') return 1;
    if(ch == 'i') return 2;
    if(ch == 'o') return 3;
    if(ch == 'u') return 4;
    return 5;
}
string s; 
int dp[N][32][6];
int magic(int pos, int mask, int last) {
    if(pos == s.size()) return 0;
    int &ans = dp[pos][mask][last];
    if(~ans) return ans;
    ans = INT_MAX;
    for(int i = 0; i < 5; i ++) {
        if(mask >> i & 1) continue;
        int op = i - f(s[pos]);
        if(op < 0) op += 5;
        ans = min(ans, op + magic(pos + 1, mask | (1 << i), i));
    }

    if(last != 5) {
        int op = last - f(s[pos]);
        if(op < 0) op += 5;
        ans = min(ans, op + magic(pos + 1, mask, last));
    }

    return ans;
}

void solve() {
    int n; cin>>n;
    cin>>s;
    // cout<<n<<" "<<s<<endl;
    
    // vector<vector<vector<int>>> dp(n, vector<vector<int>>(32, vector<int>(6, -1)));

    

    for(int i = 0; i < n; i++)
        for(int j = 0; j < 32; j++)
            for(int k = 0; k < 6; k++)
                dp[i][j][k] = -1;


    cout<<magic(0, 0, 5)<<endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1; 
    cin>>t;
    for(int tc = 1; tc <= t; tc++) {
        // cout<<"Case "<<tc<<":";
        solve();
    }
}

Information

Submit By
Type
Submission
Problem
P1140 Vowel arrangement
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-17 15:55:34
Judged At
2025-01-17 15:55:34
Judged By
Score
100
Total Time
872ms
Peak Memory
83.32 MiB