結果

問題 No.145 yukiover
ユーザー IL_mstaIL_msta
提出日時 2015-08-01 19:46:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,827 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 86,892 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-25 00:25:11
合計ジャッジ時間 2,346 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,500 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
 
#include <iostream>
#include <iomanip>
#include <sstream>
 
#include <algorithm>
#include <cmath>
 
#include <string>
//#include <array>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
 
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
 
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////

int num[512];

int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    cout << setprecision(16);//
	
	int N;
	string str;
	cin>>N>>str;

	rep(i,512){
		num[i] = 0;
	}
	rep(i,N){
		++num[ str[i] ];
	}
	int ans = 0;
	//z
	ans += num['z'];
	num['z'] = 0;

	//yv
	int it = 'u' + 1;
	for(;num['y'] && it < 'y';++it){
		if( num[it] >= num['y'] ){
			ans += num['y'];
			num[it] -= num['y'];
			num['y'] = 0;
		}else{
			ans += num[it];
			num['y'] -= num[it];
			num[it] = 0;
		}
	}
	//yul
	it = 'k'+1;
	int minel = min(num['y'],num['u']);
	for(;minel > 0 && it < 'y';++it ){
		if(it == 'u')continue;
		if( num[it] >= minel ){
			ans += minel;
			num['y'] -= minel;
			num['u'] -= minel;
			num[it] -= minel;
			minel = 0;
		}else{
			ans += num[it];
			num['y'] -= num[it];
			num['u'] -= num[it];
			minel -= num[it];
			num[it] = 0;
		}
	}

	//yukj
	it = 'i'+1;
	minel = min( min(num['y'],num['u']),num['k'] );
	for(;minel > 0 && it < 'y';++it){
		if( it == 'u' || it == 'k')continue;
		if( num[it] >= minel ){
			ans += minel;
			num['y'] -= minel;
			num['u'] -= minel;
			num['k'] -= minel;
			num[it] -= minel;
			minel = 0;
		}else{
			ans += num[it];
			num['y'] -= num[it];
			num['u'] -= num[it];
			num['k'] -= num[it];
			minel -= num[it];
			num[it] = 0;
			
		}
	}

	//yuki.*
	it = 'a';
	minel = min( min(num['y'],num['u']),min(num['k'],num['i']) );
	for(;minel > 0 && it < 'y';++it){
		if( it == 'u' || it == 'k' || it == 'i')continue;
		if(num[it] >= minel ){
			ans += minel;
			num['y'] -= minel;
			num['u'] -= minel;
			num['k'] -= minel;
			num['i'] -= minel;
			num[it] -= minel;
			minel = 0;
		}else{
			ans += num[it];
			num['y'] -= num[it];
			num['u'] -= num[it];
			num['k'] -= num[it];
			num['i'] -= num[it];
			minel -= num[it];
			num[it] = 0;
		}
	}

	//yukii
	minel = min( min(num['y'],num['u']),min(num['k'],num['i']/2) );
	ans += minel;
	num['y'] -= minel;
	num['u'] -= minel;
	num['k'] -= minel;
	num['i'] -= minel*2;

	//yukk
	minel = min( min(num['y'],num['u']) ,num['k']/2 );
	ans += minel;
	num['y'] -= minel;
	num['u'] -= minel;
	num['k'] -= minel*2;

	//yuu
	minel = min( num['y'],num['u']/2);
	ans += minel;
	num['y'] -= minel;
	num['u'] -= 2*minel;

	//yy
	ans += num['y']/2;
	num['y'] = num['y']%2;
	P(ans);
	return 0;
}
0