/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 2ms 356.0 KiB
#2 Wrong Answer 1ms 588.0 KiB

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]) 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:40
Judged At
2024-12-05 05:09:40
Judged By
Score
0
Total Time
2ms
Peak Memory
588.0 KiB