結果

問題 No.345 最小チワワ問題
ユーザー きつねうどんきつねうどん
提出日時 2023-11-24 22:59:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 1,741 bytes
コンパイル時間 2,259 ms
コンパイル使用メモリ 77,976 KB
実行使用メモリ 58,096 KB
最終ジャッジ日時 2023-11-24 22:59:18
合計ジャッジ時間 7,414 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
57,960 KB
testcase_01 AC 124 ms
57,840 KB
testcase_02 AC 125 ms
57,960 KB
testcase_03 AC 123 ms
57,964 KB
testcase_04 AC 121 ms
57,836 KB
testcase_05 AC 121 ms
57,836 KB
testcase_06 AC 121 ms
57,828 KB
testcase_07 AC 111 ms
56,692 KB
testcase_08 AC 122 ms
57,828 KB
testcase_09 AC 134 ms
57,652 KB
testcase_10 AC 127 ms
57,712 KB
testcase_11 AC 122 ms
57,676 KB
testcase_12 AC 123 ms
58,088 KB
testcase_13 AC 138 ms
57,940 KB
testcase_14 AC 125 ms
57,956 KB
testcase_15 AC 121 ms
57,948 KB
testcase_16 AC 121 ms
57,832 KB
testcase_17 AC 150 ms
57,728 KB
testcase_18 AC 124 ms
57,828 KB
testcase_19 AC 120 ms
57,836 KB
testcase_20 AC 111 ms
56,684 KB
testcase_21 AC 125 ms
57,948 KB
testcase_22 AC 121 ms
57,844 KB
testcase_23 AC 121 ms
57,840 KB
testcase_24 AC 109 ms
56,676 KB
testcase_25 AC 122 ms
58,096 KB
testcase_26 AC 133 ms
57,856 KB
testcase_27 AC 122 ms
57,824 KB
testcase_28 AC 122 ms
57,824 KB
testcase_29 AC 124 ms
57,992 KB
testcase_30 AC 122 ms
57,716 KB
testcase_31 AC 120 ms
57,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {
    public static class Pair {
        public Integer status;
        public Integer length;

        public Pair(Integer s, Integer l) {
            this.status = s;
            this.length = l;
        }


    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String a = scanner.next();
        String[] strArray = a.split("");
        List<Pair> pairList = new ArrayList<Pair>();
        for (String s : strArray) {
            if (s.equals("c")) {
                for (Pair p : pairList) {
                    if (p.status == 2) {
                        continue;
                    }
                    p.length++;
                }
                Pair pair = new Pair(0, 1);
                pairList.add(pair);
            } else if (s.equals("w")) {
                for (Pair p : pairList) {
                    if (p.status == 2) {
                        continue;
                    }
                    p.status++;
                    p.length++;
                }
            } else {
                for (Pair p : pairList) {
                    if (p.status == 2) {
                        continue;
                    }
                    p.length++;
                }
            }
        }

        int minLength = 101;
        for (Pair p : pairList) {
            if (p.status == 2) {
                if (p.length < minLength) {
                    minLength = p.length;
                }
            }
        }
        if (minLength == 101) {
            System.out.println(-1);
        } else {
            System.out.println(minLength);
        }
    }
}
0