/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 7ms 532.0 KiB
#3 Accepted 216ms 576.0 KiB
#4 Accepted 539ms 928.0 KiB
#5 Time Exceeded ≥1616ms ≥184.75 MiB
#6 Time Exceeded ≥1616ms ≥184.703 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";
map<char, int> mp;


const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const int INF = 1e18 + 10;

int n;
string s;
vector<vector<vector<int>>> dp;

int magic(int ind, int mask, int prv) {
    if(ind == n) return 0;

    int &ans = dp[ind][mask][prv];
    if(~ans) return ans;
    ans = INF;

    for(int i = 0; i < 5; i++) {
        if(mask >> i & 1) continue;
        int op = i - mp[s[ind]];
        if(op < 0) op += 5;
        ans = min(ans, op + magic(ind + 1, mask | (1LL << i), i));
    }

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

    return ans;
}

void solve() {
    cin >> n >> s;
    dp = vector<vector<vector<int>>>(n, vector<vector<int>>(32, vector<int>(6, -1)));

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

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

    
    mp['a'] = 0;
    mp['e'] = 1;
    mp['i'] = 2;
    mp['o'] = 3;
    mp['u'] = 4;

    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-07-07 09:39:27
Judged At
2025-07-07 09:39:27
Judged By
Score
10
Total Time
≥1616ms
Peak Memory
≥184.75 MiB