結果

問題 No.279 木の数え上げ
コンテスト
ユーザー kitamoto0407
提出日時 2025-12-06 10:07:46
言語 Java
(openjdk 25.0.1)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 1,385 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,014 ms
コンパイル使用メモリ 79,672 KB
実行使用メモリ 48,848 KB
最終ジャッジ日時 2025-12-06 10:07:53
合計ジャッジ時間 5,160 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.*;

class Process {
    private String S;

    Process(String S) {
        this.S = S;
    }

    int getResult() {
        // S に含まれる 't', 'r', 'e' それぞれの個数
        int[] charCounts = new int[3];

        for(int i = 0; i < S.length(); i++) {
            switch(S.charAt(i)) {
                case 't':
                    charCounts[0]++;
                    break;

                case 'r':
                    charCounts[1]++;
                    break;

                case 'e':
                    charCounts[2]++;
                    break;
            }
        }

        int count = 0;
        while((charCounts[0] > 0) && (charCounts[1] > 0) && (charCounts[2] > 1)) {
            count++;

            charCounts[0]--;
            charCounts[1]--;
            charCounts[2] -= 2;
        }

        return count;
    }
}

public class Main {
    public static void main(String[] args) throws IOException {
        var bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        var printWriter    = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        // 入力
        String S = bufferedReader.readLine().trim();

        // 処理および出力
        printWriter.println((new Process(S)).getResult());
        
        bufferedReader.close();
        printWriter.close();
    }
}
0