/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 352.0 KiB
#2 Wrong Answer 3ms 332.0 KiB
#3 Wrong Answer 85ms 564.0 KiB

Code

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

typedef long long ll;
#define bug(a) cout << #a << " : " << a << endl;

string s;
char next(char ch){
    if(ch=='a')return 'e';
    if(ch=='e')return 'i';
    if(ch=='i')return 'o';
    if(ch=='o')return 'u';
    if(ch=='u')return 'a';
}

int f(int i,int j,string &k){
    if(i==s.size()){
        return 0;
    }
    int ans=1e8;
    if(s[i]==k[j]){
        if(j!=k.size()-1){
            ans=min(ans,f(i+1,j+1,k));
            ans=min(ans,f(i+1,j,k));
        }
        else{
            ans=min(ans,f(i+1,j,k));
        }
    }
    else if(next(s[i])==k[j]){
        ans=min(ans,f(i+1,j,k)+1);
        // if(j!=k.size()-1){
        //     ans=min(ans,f(i+1,j+1,k)+1);
        // }
    }
    return ans;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;cin>>t;
    while (t--) {
        int n; cin >> n;
        cin>>s;
        // bug(1<<5)
        int ans=1e7;
        int cur=0;
        string v="aeiou";
        for(int mask=1;mask<(1<<5);mask++){
            string k="";
            for(int i=0;i<5;i++){
                if(mask&(1<<i)){
                    k+=(v[i]);
                }
            }
            // bug(k)
            sort(k.begin(),k.end());
            while(next_permutation(k.begin(),k.end())){
                ans=min(ans,f(0,0,k));
                cur++;
            }
        }
        // string k;
        // k+='a';
        // k+='e';
        // bug(s)
        // cout<<f(0,0,k)<<endl;
        // bug(cur)
        cout<<ans<<endl;
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1140 Vowel arrangement
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-12 07:31:04
Judged At
2024-12-12 07:31:04
Judged By
Score
1
Total Time
85ms
Peak Memory
564.0 KiB