/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 13ms 620.0 KiB
#3 Accepted 395ms 796.0 KiB
#4 Accepted 1179ms 844.0 KiB
#5 Time Exceeded ≥1605ms ≥190.82 MiB
#6 Time Exceeded ≥1605ms ≥191.031 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;
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 c2 = (aeiou[last]=='a' || (mask&(1<<indx['a']))==0)? tc[s[i]]['a'] + rec(i+1,mask|(1<<indx['a']),indx['a'],dp):  1e7;
    int c3 = (aeiou[last]=='e' || (mask&(1<<indx['e']))==0)? tc[s[i]]['e']+ rec(i+1,mask|(1<<indx['e']),indx['e'],dp):  1e7;
    int c4 = (aeiou[last]=='i' || (mask&(1<<indx['i']))==0)? tc[s[i]]['i'] + rec(i+1,mask|(1<<indx['i']),indx['i'],dp):  1e7;
    int c5 = (aeiou[last]=='o' || (mask&(1<<indx['o']))==0)? tc[s[i]]['o'] + rec(i+1,mask|(1<<indx['o']),indx['o'],dp):  1e7;
    int c6 = (aeiou[last]=='u' || (mask&(1<<indx['u']))==0)? tc[s[i]]['u'] + rec(i+1,mask|(1<<indx['u']),indx['u'],dp):  1e7;
    return dp[i][mask][last] = min({c2,c3,c4,c5,c6});
}

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:29:24
Judged At
2024-12-12 15:29:24
Judged By
Score
10
Total Time
≥1605ms
Peak Memory
≥191.031 MiB