/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 10ms 540.0 KiB
#3 Accepted 347ms 540.0 KiB
#4 Accepted 727ms 572.0 KiB
#5 Accepted 1008ms 6.004 MiB
#6 Accepted 1000ms 6.172 MiB
#7 Accepted 974ms 3.484 MiB
#8 Accepted 883ms 1.309 MiB
#9 Accepted 553ms 576.0 KiB
#10 Accepted 375ms 588.0 KiB
#11 Accepted 989ms 6.254 MiB
#12 Accepted 1021ms 6.051 MiB
#13 Accepted 999ms 6.012 MiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=2e5+10,MOD=1000000007;
typedef long long ll;
int cost[26][26];
vector<string>all;
void precal(){
	string vowel="aeiou";
	for(int i=0;i<(int)vowel.size();i++){
		int l=i;
		int cnt=0;
		while(cnt<5){
			cost[vowel[i]-'a'][vowel[l]-'a']=cnt;
			l++;
			cnt++;
			if(l==5)l=0;
			
		}
		
	}
	all.push_back(vowel);
	while(next_permutation(vowel.begin(),vowel.end())){
		all.push_back(vowel);
	}
	
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    precal();
    cin>>t;
    while(t--){
    	int n;
    	cin>>n;
    	string s;
    	cin>>s;
    	int mx=1e9;
    	for(auto it:all){
    		string p=it;
    		vector<vector<int>>dp(n+1,vector<int>(5,0));
    		for(int i=0;i<5;i++){
    			for(int j=1;j<=n;j++)
    			{
    				int pro=cost[s[j-1]-'a'][p[i]-'a'];
    				if(i==0){
    					dp[j][i]=dp[j-1][i]+pro;
    				}
    				else{
    					dp[j][i]=dp[j-1][i]+pro;
    					dp[j][i]=min(dp[j][i],dp[j][i-1]);
    				}
    			}
    			mx=min(mx,dp[n][i]);
    		}
    	}
    	cout<<mx<<"\n";
    	
    	
   
     

    
    
}

    
    return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1140 Vowel arrangement
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-27 11:05:04
Judged At
2024-12-08 18:29:22
Judged By
Score
100
Total Time
1021ms
Peak Memory
6.254 MiB