結果

問題 No.145 yukiover
ユーザー GrenacheGrenache
提出日時 2016-05-23 20:16:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 3,428 bytes
コンパイル時間 3,794 ms
コンパイル使用メモリ 80,476 KB
実行使用メモリ 39,576 KB
最終ジャッジ日時 2024-10-07 01:48:46
合計ジャッジ時間 5,892 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
36,972 KB
testcase_01 AC 48 ms
36,944 KB
testcase_02 AC 53 ms
36,760 KB
testcase_03 AC 48 ms
36,924 KB
testcase_04 AC 48 ms
37,132 KB
testcase_05 AC 49 ms
37,060 KB
testcase_06 AC 48 ms
36,844 KB
testcase_07 AC 47 ms
37,112 KB
testcase_08 AC 47 ms
36,992 KB
testcase_09 AC 47 ms
37,144 KB
testcase_10 AC 46 ms
36,588 KB
testcase_11 AC 81 ms
39,576 KB
testcase_12 AC 87 ms
39,464 KB
testcase_13 AC 85 ms
39,132 KB
testcase_14 AC 85 ms
39,324 KB
testcase_15 AC 88 ms
39,320 KB
testcase_16 AC 74 ms
39,388 KB
testcase_17 AC 82 ms
38,984 KB
testcase_18 AC 83 ms
39,252 KB
testcase_19 AC 83 ms
39,388 KB
testcase_20 AC 83 ms
39,204 KB
testcase_21 AC 83 ms
38,892 KB
testcase_22 AC 84 ms
39,528 KB
testcase_23 AC 85 ms
39,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder145 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Printer pr = new Printer(System.out);

        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        n = s.length;

        int[] cnt = new int[26];
        for (int i = 0; i < n; i++) {
        	cnt[s[i] - 'a']++;
        }

        int cz = cnt['z' - 'a'];
        int cy = cnt['y' - 'a'];
        int cvwx = cnt['v' - 'a'] + cnt['w' - 'a'] + cnt['x' - 'a'];
        int cu = cnt['u' - 'a'];
        int clt = cnt['l' - 'a'] + cnt['m' - 'a'] + cnt['n' - 'a'] + cnt['o' - 'a'] + cnt['p' - 'a'] + cnt['q' - 'a'] + cnt['r' - 'a'] + cnt['s' - 'a'] + cnt['t' - 'a'];
        int ck = cnt['k' - 'a'];
        int cj = cnt['j' - 'a'];
        int ci = cnt['i' - 'a'];
        int cah = cnt['a' - 'a'] + cnt['b' - 'a'] + cnt['c' - 'a'] + cnt['d' - 'a'] + cnt['e' - 'a'] + cnt['f' - 'a'] + cnt['g' - 'a'] + cnt['h' - 'a'];

        int ret = cz;

        // -----------------------------------------
        int tmp = Math.min(Math.min(Math.min(cy, cu), ck), ci);
        tmp = Math.min(tmp, cah);
    	ret += tmp;
    	cy -= tmp;
    	cu -= tmp;
    	ck -= tmp;
    	ci -= tmp;
    	cah -= tmp;

        tmp = Math.min(Math.min(Math.min(cy, cu), ck), ci / 2);
        ret += tmp;
        cy -= tmp;
        cu -= tmp;
        ck -= tmp;
        ci -= tmp * 2;
        // -----------------------------------------
        tmp = Math.min(Math.min(cy, cu), ck);
        tmp = Math.min(tmp, cj);
        ret += tmp;
        cy -= tmp;
        cu -= tmp;
        ck -= tmp;
        cj -= tmp;

        tmp = Math.min(Math.min(cy, cu), ck / 2);
        ret += tmp;
        cy -= tmp;
        cu -= tmp;
        ck -= tmp * 2;
        // -----------------------------------------
        tmp = Math.min(cy, cu);
        tmp = Math.min(tmp, clt);
        ret += tmp;
        cy -= tmp;
        cu -= tmp;
        clt -= tmp;

        tmp = Math.min(cy, cu / 2);
        ret += tmp;
        cy -= tmp;
        cu -= tmp * 2;
        // -----------------------------------------
        tmp = Math.min(cy, cvwx);
        ret += tmp;
        cy -= tmp;
        cvwx -= tmp;

        ret += cy / 2;
        // -----------------------------------------

        pr.println(ret);

        pr.close();
        sc.close();
    }

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0