/ SeriousOJ /

Record Detail

Compile Error

foo.cc: In function 'void taking(std::set<char>)':
foo.cc:25:13: error: 'class std::map<std::set<char>, int>' has no member named 'contains'
   25 |     if(type.contains(s))    return;
      |             ^~~~~~~~
foo.cc:31:15: error: 'class std::set<char>' has no member named 'contains'
   31 |         if(!t.contains(c)){
      |               ^~~~~~~~
foo.cc: In function 'int f(int, std::set<char>, char)':
foo.cc:47:13: error: 'class std::set<char>' has no member named 'contains'
   47 |     if(!tmp.contains(st[i])){
      |             ^~~~~~~~
foo.cc:53:15: error: 'class std::set<char>' has no member named 'contains'
   53 |         if(!t.contains(c)){
      |               ^~~~~~~~

Code

/**
*  Problem Name: Vowel_arrangement
*  Author: MJS
*  Created: 12 December 2024, Thursday (13:02:07)...
**/

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define nl '\n' 
#define N 100003

string v="aeiou";
map<pair<char,char>,int> cost;
map<set<char>,int> type;
map<char,int> id;

int n;
string st;
vector<vector<vector<int>>> dp;
// int dp[N][33][6];,

void taking(set<char> s){
    if(type.contains(s))    return;

    type[s]=type.size();

    for(auto &c: v){
        auto t=s;
        if(!t.contains(c)){
            t.insert(c);
            taking(t);
        }
        taking(s);
    }
}

int f(int i,set<char> s,char lst){
    if(i==n)    return 0;
    
    int j=type[s],k=id[lst];
    if(dp[i][j][k]!=-1)    return dp[i][j][k];

    int take=1e8,not_take=1e8;
    auto tmp=s;
    if(!tmp.contains(st[i])){
        if(lst!='*' && st[i]!=lst)  tmp.insert(lst);
        not_take=0+f(i+1,tmp,st[i]);
    }
    for(auto &c: v){
        auto t=s;
        if(!t.contains(c)){
            if(lst!='*' && c!=lst)  t.insert(lst);
            take=min(take,cost[{st[i],c}]+f(i+1,t,c));
        }
    }
    return dp[i][j][k]=min(take,not_take);
}

void answer_to_the_question(){
    cin>>n>>st;
    dp=vector(n+2,vector(33,vector(6,-1)));

    set<char> tmp;
    cout<<f(0,tmp,'*')<<nl;
}

int32_t main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int test_case;    cin>>test_case;

    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            cost[{v[i],v[j]}]=(10+j-i)%5;
        }
    }
    set<char> s;
    taking(s);
    for(int i=0;i<5;i++)    id[v[i]]=i+1;
    id['*']=0;

    for(int MJS=1; MJS<=test_case; MJS++){
        answer_to_the_question();
    }

    return 0;
}

// Hi..

Information

Submit By
Type
Submission
Problem
P1140 Vowel arrangement
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-12 08:20:37
Judged At
2024-12-12 08:20:37
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes