結果

問題 No.145 yukiover
ユーザー htensaihtensai
提出日時 2020-05-14 16:33:00
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,372 bytes
コンパイル時間 2,046 ms
コンパイル使用メモリ 74,228 KB
実行使用メモリ 57,272 KB
最終ジャッジ日時 2023-10-13 14:05:08
合計ジャッジ時間 7,037 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
55,948 KB
testcase_01 AC 109 ms
56,072 KB
testcase_02 AC 111 ms
56,512 KB
testcase_03 AC 108 ms
55,892 KB
testcase_04 AC 110 ms
56,108 KB
testcase_05 WA -
testcase_06 AC 109 ms
56,196 KB
testcase_07 AC 112 ms
56,252 KB
testcase_08 AC 121 ms
55,460 KB
testcase_09 AC 121 ms
55,832 KB
testcase_10 WA -
testcase_11 AC 188 ms
55,964 KB
testcase_12 WA -
testcase_13 AC 199 ms
56,980 KB
testcase_14 AC 194 ms
56,540 KB
testcase_15 AC 187 ms
56,200 KB
testcase_16 AC 181 ms
56,656 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 178 ms
56,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int total = 0;
		int[] counts = new int[6]; // y - u - k -
		for (char c : arr) {
		    if (c > 'y') {
		        total++;
		    } else if (c == 'y') {
		        counts[0]++;
		    } else if (c > 'u') {
		        counts[1]++;
		    } else if (c == 'u') {
		        counts[2]++;
		    } else if (c > 'k') {
		        counts[3]++;
		    } else if (c == 'k') {
		        counts[4]++;
		    } else if (c > 'i') {
		        counts[5]++;
		    }
		}
		if (counts[4] > counts[5]) {
		    int sum = counts[4] + counts[5];
		    counts[4] = sum / 2;
		    counts[5] = sum / 2;
		}
	    int cnt = Math.min(Math.min(counts[0], counts[2]), Math.min(counts[4], counts[5]));
	    total += cnt;
	    counts[0] -= cnt;
	    counts[2] -= cnt;
		if (counts[2] > counts[3]) {
		    int sum = counts[2] + counts[3];
		    counts[2] = sum / 2;
		    counts[3] = sum / 2;
		}
	    cnt = Math.min(counts[0], Math.min(counts[2], counts[3]));
	    total += cnt;
	    counts[0] -= cnt;
		if (counts[0] > counts[1]) {
		    int sum = counts[0] + counts[1];
		    counts[0] = sum / 2;
		    counts[1] = sum / 2;
		}
	    cnt = Math.min(counts[0], counts[1]);
	    total += cnt;
		System.out.println(total);
	}
}
0