/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 3ms 608.0 KiB
#3 Accepted 51ms 592.0 KiB
#4 Accepted 163ms 2.777 MiB
#5 Accepted 418ms 156.688 MiB
#6 Accepted 414ms 155.312 MiB
#7 Accepted 404ms 78.652 MiB
#8 Accepted 244ms 17.23 MiB
#9 Accepted 121ms 584.0 KiB
#10 Accepted 79ms 728.0 KiB
#11 Accepted 421ms 155.727 MiB
#12 Accepted 421ms 156.52 MiB
#13 Accepted 415ms 155.398 MiB

Code

// #pragma GCC optimize("O3,unroll-loops,Ofast")
// #pragma GCC target("avx2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define endl '\n'

using namespace std;
using pii = pair<int, int>;
using tup = tuple<int, int, int>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T> using ordered_set = tree<T, null_type,
                         less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int inf = 1e18;
const int mod = 1000000007;
const double eps = 1e-9;
const int N = 200005;

void preprocess() {}

int n;
string s;

int v[] = {'a', 'e', 'i', 'o', 'u'};
int wer[256];
int dp[N][6][1<<5];

int DP(int i, int taking, int mask) {
    if(i == n) return 0;

    if(dp[i][taking+1][mask] != -1) return dp[i][taking+1][mask];
    int ret = inf;
    if(taking > -1) ret = DP(i+1, taking, mask) + (taking-wer[s[i]]+5)%5;

    for(int c=0; c<5; c++) {
        if((mask >> c) & 1) continue;
        ret = min(ret, DP(i+1, c, mask | (1 << c)) + (c-wer[s[i]]+5)%5);
    }

    return dp[i][taking+1][mask] = ret;
}

void solve(int tc) {
    cin >> n >> s;
    for(int i=0; i<=n; i++) memset(dp[i], -1, sizeof dp[i]);

    for(int i=0; i<5; i++) wer[v[i]] = i;
    cout << DP(0, -1, 0) << endl;
}
     
int32_t main() {
    cin.tie(NULL)->sync_with_stdio(false);
    cout.precision(10);

    preprocess(); 

    int T = 1;
    cin >> T;

    for (int i = 1; i <= T; i++) {
        solve(i);
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1140 Vowel arrangement
Contest
LU Divisonal Contest Problem Testing Round
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-05 05:09:58
Judged At
2024-12-08 18:32:35
Judged By
Score
100
Total Time
421ms
Peak Memory
156.688 MiB