/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 13ms 768.0 KiB
#3 Accepted 464ms 580.0 KiB
#4 Accepted 1428ms 796.0 KiB
#5 Time Exceeded ≥1536ms ≥70.84 MiB
#6 Accepted 1273ms 71.078 MiB
#7 Accepted 1180ms 37.551 MiB
#8 Accepted 1149ms 9.027 MiB
#9 Accepted 1040ms 796.0 KiB
#10 Accepted 636ms 636.0 KiB
#11 Accepted 1177ms 71.082 MiB
#12 Accepted 1178ms 71.074 MiB
#13 Accepted 824ms 71.102 MiB

Code

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

#define nl '\n'
#define ll long long
// #define int long long
#define pii pair<int, int> 

const int N = 1e5+5;
const int inf = 2e9;
int n;
string s, t = "aeiouaeiou";

int chk(char x, char c){
    int ret = 0, id = 0;
    while(t[id]!= x) id++;
    while(t[id]!= c) id++, ret++;
    return ret;
}

int dp[N][5][(1<<5)];

int go(int pos, int c, int mask){
    if(pos == n) return 0;
    if(__builtin_popcount(mask) == 5) return inf;
    int &ret = dp[pos][c][mask];
    if(~ret) return ret;
    int ans = inf;
    ans = min(ans, chk(s[pos], t[c]) + go(pos+1, c, mask));
    for(int i=0;i<5;++i){
        if(mask&(1<<i)) continue;
        ans = min(ans, chk(s[pos], t[i]) + go(pos+1, i, mask|(1<<c)));
    }
    return ret = ans;
}

void solve(){
    cin >> n >> s;
    int ans = inf;
    for(int i=0;i<=n;++i){
        memset(dp[i], -1, sizeof dp[i]);
    }
    for(int i=0;i<5;++i){
        ans = min(ans, (go(0,i,0)==-1?inf:go(0,i,0)));
        //
    }
    cout << ans << nl;
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1, tc = 0;
    cin >> t ;
    while(t--){
        // cout << "Case " << ++tc  << ": ";
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1140 Vowel arrangement
Contest
LU IUJPC : Sylhet Division 2024
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-09 09:14:48
Judged At
2024-12-09 09:14:48
Judged By
Score
90
Total Time
≥1536ms
Peak Memory
≥71.102 MiB