/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 13ms 572.0 KiB
#3 Accepted 629ms 596.0 KiB
#4 Accepted 743ms 580.0 KiB
#5 Accepted 650ms 8.402 MiB
#6 Accepted 679ms 8.402 MiB
#7 Accepted 652ms 6.48 MiB
#8 Accepted 651ms 1.359 MiB
#9 Accepted 1063ms 588.0 KiB
#10 Accepted 406ms 576.0 KiB
#11 Accepted 649ms 8.402 MiB
#12 Accepted 652ms 8.398 MiB
#13 Accepted 595ms 8.402 MiB

Code

//SUST_ZadeedBoss_Fanclub
//code_korlei_life_ase
//na_korle_lifeNai

#include<bits/stdc++.h>
using namespace std;
#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, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define double long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); 

int dp[100005][10];
map <pair <char, char>, int> mp;


int move (char x, char y)
{
	return mp[{x, y}];
}
void solve ()
{
	int n; cin >>n; n++;
	string s; cin >>s; s= "$" + s;
	vector <char> v = {'a', 'e', 'i', 'o', 'u'};
	for (int i=0; i<5; i++)
	{
		for (int j=0; j<5; j++)
		{
			mp[{v[i], v[j]}] = (j-i+10)%5;
			// cout<<i <<" " <<j <<v[i] <<" " <<v[j] <<" " <<mp[{v[i], v[j]}] <<"\n";
		}
	}
	int ans = 1e9;
	while (1)
	{

		for (int i=1; i<n; i++)
		{
			dp[i][0] = dp[i-1][0] + move(s[i], v[0]);
			for (int j=1; j<5; j++)
			{
				dp[i][j] = min(dp[i-1][j-1], dp[i-1][j]) + move(s[i], v[j]);
				dp[i][j] = min(dp[i][j], dp[i][j-1]);
			}
		}
		for (int j=0; j<5; j++)
		{
			ans = min(ans, dp[n-1][j]);
		}

		next_permutation(all(v));
		if (is_sorted(all(v))) break;
	}
	cout <<ans <<"\n";

}

signed main()
{

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	int TCASE = 1;
	cin >> TCASE;

	for (int tcase = 1; tcase <= TCASE; tcase++)
	{
		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:10:04
Judged At
2024-12-09 09:10:04
Judged By
Score
100
Total Time
1063ms
Peak Memory
8.402 MiB