結果

問題 No.345 最小チワワ問題
ユーザー yagi2yagi2
提出日時 2017-04-20 12:40:22
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,100 bytes
コンパイル時間 2,028 ms
コンパイル使用メモリ 74,448 KB
実行使用メモリ 58,292 KB
最終ジャッジ日時 2023-09-27 03:16:56
合計ジャッジ時間 6,817 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 106 ms
56,040 KB
testcase_08 AC 106 ms
56,128 KB
testcase_09 AC 99 ms
55,728 KB
testcase_10 WA -
testcase_11 AC 109 ms
56,440 KB
testcase_12 AC 115 ms
56,056 KB
testcase_13 AC 111 ms
55,324 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 104 ms
56,076 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 98 ms
55,848 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 102 ms
55,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();

        List<Integer> cwwList = new ArrayList<>();
        for (int i = 0; i < S.length() - 1; i++) {
            int n = 0;
            if (S.charAt(i) == 'c') {
                int wwCount = 0;
                for (int j = i+1; j < S.length(); j++) {
                   if (S.charAt(j) == 'w') wwCount++;
                   if (wwCount == 2) {
                       n = j+1;
                       break;
                   }

                }
            }
            n -= i;
            if (n > 0) {
                System.out.println(n);
                cwwList.add(n);
            }
        }

        if (cwwList.size() == 0) {
            System.out.println("-1");
        } else {
            int min = Integer.MAX_VALUE;
            for (Integer n : cwwList) {
                if (min > n) min = n;
            }
            System.out.println(min);
        }
    }
}
0