/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 516.0 KiB
#2 Wrong Answer 25ms 580.0 KiB
#3 Wrong Answer 900ms 596.0 KiB

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 mvv[6][6] = {{0,1,2,3,4}, {5,0,1,2,3,4},{4, 5, 0, 1,2,3},{3,4, 5, 0, 1,2}, {2,3,4, 5, 0, 1}, {1,2,3,4, 5, 0}};

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

unordered_map<char, int> um;

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, mvv[um[s[pos]]][um[t[c]]] + go(pos+1, c, mask));
    for(int i=0;i<5;++i){
        if(mask&(1<<i)) continue;
        ans = min(ans, mvv[um[s[pos]]][um[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);
    um['a']=0;
    um['e']=1;
    um['i']=2;
    um['o']=3;
    um['u']=4;
    // for(int i=0;i<5;++i){
    //     for(int j=0;j<5;++j){
    //         cout << mvv[i][j] << " \n"[j==4];
    //         // if(i==j) mvv[t[i]][t[j]] = 0;
    //         // else mvv[t[i]+'a'][t[j]+'a'] = chk(t[i], t[j]);
    //     }
    // }

    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:30:32
Judged At
2024-12-09 09:30:32
Judged By
Score
1
Total Time
900ms
Peak Memory
596.0 KiB