結果

問題 No.145 yukiover
ユーザー GrenacheGrenache
提出日時 2016-05-23 20:16:37
言語 Java19
(openjdk 21)
結果
AC  
実行時間 84 ms / 5,000 ms
コード長 3,428 bytes
コンパイル時間 4,222 ms
コンパイル使用メモリ 75,672 KB
実行使用メモリ 52,456 KB
最終ジャッジ日時 2023-07-29 01:41:55
合計ジャッジ時間 6,745 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,316 KB
testcase_01 AC 45 ms
49,596 KB
testcase_02 AC 45 ms
49,392 KB
testcase_03 AC 45 ms
49,364 KB
testcase_04 AC 46 ms
49,536 KB
testcase_05 AC 45 ms
49,228 KB
testcase_06 AC 47 ms
49,360 KB
testcase_07 AC 48 ms
49,244 KB
testcase_08 AC 45 ms
49,308 KB
testcase_09 AC 43 ms
49,396 KB
testcase_10 AC 44 ms
49,656 KB
testcase_11 AC 81 ms
51,920 KB
testcase_12 AC 71 ms
52,456 KB
testcase_13 AC 72 ms
52,440 KB
testcase_14 AC 72 ms
50,136 KB
testcase_15 AC 72 ms
52,300 KB
testcase_16 AC 72 ms
52,048 KB
testcase_17 AC 72 ms
50,352 KB
testcase_18 AC 84 ms
52,000 KB
testcase_19 AC 72 ms
52,256 KB
testcase_20 AC 74 ms
51,908 KB
testcase_21 AC 76 ms
52,172 KB
testcase_22 AC 71 ms
52,032 KB
testcase_23 AC 76 ms
51,860 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