結果

問題 No.345 最小チワワ問題
ユーザー きつねうどんきつねうどん
提出日時 2023-11-24 23:03:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 1,333 bytes
コンパイル時間 2,490 ms
コンパイル使用メモリ 77,764 KB
実行使用メモリ 58,192 KB
最終ジャッジ日時 2023-11-24 23:03:40
合計ジャッジ時間 8,102 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
57,964 KB
testcase_01 AC 127 ms
57,816 KB
testcase_02 AC 129 ms
57,836 KB
testcase_03 AC 128 ms
57,972 KB
testcase_04 AC 128 ms
57,832 KB
testcase_05 AC 147 ms
57,956 KB
testcase_06 AC 127 ms
57,848 KB
testcase_07 AC 127 ms
57,856 KB
testcase_08 AC 128 ms
57,856 KB
testcase_09 AC 126 ms
57,940 KB
testcase_10 AC 129 ms
57,960 KB
testcase_11 AC 130 ms
57,972 KB
testcase_12 AC 133 ms
57,972 KB
testcase_13 AC 133 ms
58,096 KB
testcase_14 AC 133 ms
57,840 KB
testcase_15 AC 132 ms
57,968 KB
testcase_16 AC 127 ms
57,852 KB
testcase_17 AC 130 ms
57,708 KB
testcase_18 AC 132 ms
57,960 KB
testcase_19 AC 129 ms
57,988 KB
testcase_20 AC 133 ms
58,192 KB
testcase_21 AC 130 ms
57,820 KB
testcase_22 AC 130 ms
57,840 KB
testcase_23 AC 128 ms
57,940 KB
testcase_24 AC 127 ms
57,820 KB
testcase_25 AC 127 ms
57,972 KB
testcase_26 AC 130 ms
57,964 KB
testcase_27 AC 129 ms
57,968 KB
testcase_28 AC 130 ms
57,964 KB
testcase_29 AC 140 ms
57,960 KB
testcase_30 AC 133 ms
57,704 KB
testcase_31 AC 128 ms
57,968 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) {
            for (Pair p : pairList) {
                if (p.status == 2) {
                    continue;
                }
                if (s.equals("w")) {
                    p.status++;
                }
                p.length++;
            }
            if (s.equals("c")) {
                Pair pair = new Pair(0, 1);
                pairList.add(pair);
            }
        }

        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