/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 328.0 KiB
#2 Accepted 10ms 328.0 KiB
#3 Accepted 277ms 584.0 KiB
#4 Accepted 838ms 648.0 KiB
#5 Time Exceeded ≥1561ms ≥86.184 MiB
#6 Time Exceeded ≥1531ms ≥86.27 MiB

Code

#include<bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse, sse2, sse3, sse4, popcnt, abm, mmx, avx, tune=native")

using namespace std;

// #define int long long
#define endl "\n"
#define F first
#define S second
#define pii pair<int, int>
#define sz(x) (int) (x.size())


// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// template<typename T> using o_set = tree<T, null_type, std::less<T>, 
// rb_tree_tag, tree_order_statistics_node_update>;

string tmp = "aeiou";


const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const int INF = 1e9 + 10;


void solve() {
    int n; cin>>n;
    string s; cin>>s;
    // cout<<n<<" "<<s<<endl;
    auto mp = [&] (char ch) {
        if(ch == 'a') return 0;
        if(ch == 'e') return 1;
        if(ch == 'i') return 2;
        if(ch == 'o') return 3;
        if(ch == 'u') return 4;
    };
    // vector<vector<vector<int>>> dp(n, vector<vector<int>>(32, vector<int>(6, -1)));

    int dp[n][32][6];

    for(int i = 0; i < n; i++)
        for(int j = 0; j < 32; j++)
            for(int k = 0; k < 6; k++)
                dp[i][j][k] = -1;

    function<int(int, int, int)> magic = [&] (int ind, int mask, int prv) {
        if(ind == n) {
            return 0;
        }


        int &ans = dp[ind][mask][prv];
        if(~ans) return ans;
        ans = INF;

        for(int op = 0; op <= 4; op++) {
            int cur = (mp(s[ind]) + op);
            if(cur >= 5) cur -= 5;
            int f = (cur != prv);
            if(f && (mask & (1LL << cur))) continue;
            ans = min(ans, op + magic(ind + 1, mask | (1LL << cur), cur));
        }

        // cerr<<"ans: "<<ans<<endl;

        return ans;
    };

    cout<<magic(0, 0, 5)<<endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1; 
    cin>>t;
    for(int tc = 1; tc <= t; tc++) {
        // cout<<"Case "<<tc<<":";
        solve();
    }
}

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:01:00
Judged At
2024-12-09 09:01:05
Judged By
Score
10
Total Time
≥1561ms
Peak Memory
≥86.27 MiB