結果

問題 No.345 最小チワワ問題
ユーザー yagi2yagi2
提出日時 2017-04-20 12:41:42
言語 Java19
(openjdk 21)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 1,061 bytes
コンパイル時間 4,008 ms
コンパイル使用メモリ 76,072 KB
実行使用メモリ 57,748 KB
最終ジャッジ日時 2023-10-26 04:08:25
合計ジャッジ時間 9,484 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
57,312 KB
testcase_01 AC 130 ms
57,504 KB
testcase_02 AC 131 ms
57,396 KB
testcase_03 AC 129 ms
57,432 KB
testcase_04 AC 130 ms
57,600 KB
testcase_05 AC 134 ms
57,440 KB
testcase_06 AC 130 ms
57,516 KB
testcase_07 AC 132 ms
57,480 KB
testcase_08 AC 129 ms
57,700 KB
testcase_09 AC 131 ms
57,480 KB
testcase_10 AC 129 ms
57,472 KB
testcase_11 AC 129 ms
57,424 KB
testcase_12 AC 131 ms
57,516 KB
testcase_13 AC 130 ms
57,176 KB
testcase_14 AC 135 ms
57,716 KB
testcase_15 AC 131 ms
55,624 KB
testcase_16 AC 133 ms
57,748 KB
testcase_17 AC 130 ms
57,472 KB
testcase_18 AC 132 ms
57,600 KB
testcase_19 AC 130 ms
57,432 KB
testcase_20 AC 125 ms
57,464 KB
testcase_21 AC 131 ms
57,444 KB
testcase_22 AC 129 ms
57,592 KB
testcase_23 AC 132 ms
57,300 KB
testcase_24 AC 132 ms
57,572 KB
testcase_25 AC 134 ms
57,508 KB
testcase_26 AC 132 ms
57,436 KB
testcase_27 AC 131 ms
57,508 KB
testcase_28 AC 128 ms
57,292 KB
testcase_29 AC 133 ms
57,240 KB
testcase_30 AC 128 ms
57,244 KB
testcase_31 AC 129 ms
57,612 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) {
                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