/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 796.0 KiB
#2 Accepted 5ms 636.0 KiB
#3 Accepted 126ms 796.0 KiB
#4 Accepted 320ms 776.0 KiB
#5 Accepted 1005ms 183.238 MiB
#6 Accepted 982ms 183.137 MiB
#7 Accepted 899ms 91.977 MiB
#8 Accepted 583ms 18.852 MiB
#9 Accepted 224ms 608.0 KiB
#10 Accepted 159ms 800.0 KiB
#11 Accepted 964ms 183.227 MiB
#12 Accepted 1000ms 183.328 MiB
#13 Accepted 984ms 183.203 MiB

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define life_is_a_race ios::sync_with_stdio(false); cin.tie(nullptr);
//map<pair<char,char>,int> tc;
//unordered_map<char,int> indx;
int indx[256];
string aeiou = "aeiou",s;
int n,tc[256][256];

int rec(int i,int mask,int last,vector<vector<vector<int>>>&dp)
{
    if(i==n) return 0;
    if(dp[i][mask][last] != -1) return dp[i][mask][last];
    int x = 10000000;
    x = min(x,(aeiou[last]=='a' || (mask&(1<<indx['a']))==0)? tc[s[i]]['a'] + rec(i+1,mask|(1<<indx['a']),indx['a'],dp):  10000000);
    x = min(x,(aeiou[last]=='e' || (mask&(1<<indx['e']))==0)? tc[s[i]]['e'] + rec(i+1,mask|(1<<indx['e']),indx['e'],dp):  10000000);
    x = min(x,(aeiou[last]=='i' || (mask&(1<<indx['i']))==0)? tc[s[i]]['i'] + rec(i+1,mask|(1<<indx['i']),indx['i'],dp):  10000000);
    x = min(x,(aeiou[last]=='o' || (mask&(1<<indx['o']))==0)? tc[s[i]]['o'] + rec(i+1,mask|(1<<indx['o']),indx['o'],dp):  10000000);
    x = min(x,(aeiou[last]=='u' || (mask&(1<<indx['u']))==0)? tc[s[i]]['u'] + rec(i+1,mask|(1<<indx['u']),indx['u'],dp):  10000000);
    return dp[i][mask][last] = x;
}

void solve(int tc)
{
    cin >> n;
    cin >> s;
    vector<vector<vector<int>>> dp(n+1,vector<vector<int>>(32,vector<int>(6,-1)));
    cout<<rec(0,0,indx[s[0]],dp)<<endl;
}

int main()
{
    life_is_a_race
    tc['a']['e']=1; tc['a']['i']=2; tc['a']['o']=3; tc['a']['u']=4;
    tc['e']['i']=1; tc['e']['o']=2; tc['e']['u']=3; tc['e']['a']=4;
    tc['i']['o']=1; tc['i']['u']=2; tc['i']['a']=3; tc['i']['e']=4;
    tc['o']['u']=1; tc['o']['a']=2; tc['o']['e']=3; tc['o']['i']=4;
    tc['u']['a']=1; tc['u']['e']=2; tc['u']['i']=3; tc['u']['o']=4;

    indx['a']=0; indx['e']=1; indx['i']=2; indx['o']=3; indx['u']=4;
    int t=1; 
    cin>>t;
    for(int i=1;i<=t;i++) solve(i);
}

Information

Submit By
Type
Submission
Problem
P1140 Vowel arrangement
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-12 15:51:41
Judged At
2024-12-12 15:51:41
Judged By
Score
100
Total Time
1005ms
Peak Memory
183.328 MiB