結果
問題 | No.279 木の数え上げ |
ユーザー | nihi9119 |
提出日時 | 2017-05-31 18:12:46 |
言語 | Java21 (openjdk 21) |
結果 |
MLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,428 bytes |
コンパイル時間 | 3,448 ms |
コンパイル使用メモリ | 77,200 KB |
実行使用メモリ | 64,232 KB |
最終ジャッジ日時 | 2023-12-14 00:18:30 |
合計ジャッジ時間 | 9,901 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 80 ms
54,864 KB |
testcase_01 | AC | 64 ms
54,276 KB |
testcase_02 | AC | 82 ms
55,168 KB |
testcase_03 | AC | 65 ms
54,252 KB |
testcase_04 | AC | 59 ms
54,252 KB |
testcase_05 | AC | 68 ms
54,640 KB |
testcase_06 | AC | 62 ms
54,368 KB |
testcase_07 | AC | 63 ms
54,268 KB |
testcase_08 | AC | 80 ms
55,028 KB |
testcase_09 | AC | 59 ms
54,256 KB |
testcase_10 | AC | 478 ms
62,392 KB |
testcase_11 | AC | 260 ms
57,464 KB |
testcase_12 | AC | 432 ms
60,972 KB |
testcase_13 | AC | 164 ms
57,512 KB |
testcase_14 | AC | 482 ms
63,224 KB |
testcase_15 | MLE | - |
testcase_16 | AC | 443 ms
61,176 KB |
testcase_17 | AC | 477 ms
62,596 KB |
testcase_18 | AC | 359 ms
59,176 KB |
testcase_19 | AC | 458 ms
62,720 KB |
testcase_20 | AC | 481 ms
62,056 KB |
ソースコード
package test_5; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * No.279 木の数え上げ * kamipeipaa君は木が大好きですが,今日は文字列で遊んでいます。 * kamipeipaa君は文字列SSを並び替えたときに"tree"という * 部分文字列をいくつ作ることが可能か興味があります。 * 教えてあげてください。 */ public class Question_09_0531 { static final int LENGTH_MIN = 1; static final int LENGTH_MAX = (int)Math.pow(10, 6); static final String KEY_T = "t"; static final String KEY_R = "r"; static final String KEY_E = "e"; public static void main(String[] args) { InputStreamReader re = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(re); try { String kamipeipaa = br.readLine(); if (LengthJudg(kamipeipaa, LENGTH_MIN, LENGTH_MAX)) { int treeCount = 0; //それぞれの文字の個数を調べる("t","r","e") int cntT = kamipeipaa.replaceAll("[^" + KEY_T + "]", "").length(); int cntR = kamipeipaa.replaceAll("[^" + KEY_R + "]", "").length(); int cntE = kamipeipaa.replaceAll("[^" + KEY_E + "]", "").length(); int cntTCount = cntT / 1; int cntRCount = cntR / 1; int cntECount = cntE / 2; if (cntTCount >= 1 && cntRCount >= 1 && cntECount >= 1) { //最小値取得 int min = 0; min = Math.min(cntTCount, cntRCount); min = Math.min(min, cntECount); treeCount = min; } else { treeCount = 0; } System.out.println(treeCount); } else { System.out.println("文字列の長さが有効範囲外です"); } } catch (NumberFormatException e) { System.out.println("数字を入力して下さい。"); } catch (IOException e) { System.out.println("エラーが発生しました。"); } finally { try { re.close(); br.close(); } catch (IOException e) { System.out.println("InputStreamReader、BufferedReaderクローズ中にエラーが発生しました"); } } } /** * 有効値判定 * @param str 判定する文字列 * @param max 最大値 * @param min 最小値 * @return 範囲内ならtrue,範囲外ならfalseを返す */ private static boolean LengthJudg(String str, int min, int max) { Boolean result = false; if (min <= str.length() && str.length() <= max) { result = true; } return result; } }