結果

問題 No.345 最小チワワ問題
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-12 19:07:20
言語 Java19
(openjdk 21)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 661 bytes
コンパイル時間 2,848 ms
コンパイル使用メモリ 74,772 KB
実行使用メモリ 57,672 KB
最終ジャッジ日時 2023-10-26 04:05:14
合計ジャッジ時間 8,486 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
57,280 KB
testcase_01 AC 131 ms
57,268 KB
testcase_02 AC 133 ms
57,312 KB
testcase_03 AC 131 ms
57,252 KB
testcase_04 AC 128 ms
57,252 KB
testcase_05 AC 131 ms
57,244 KB
testcase_06 AC 129 ms
57,328 KB
testcase_07 AC 128 ms
57,280 KB
testcase_08 AC 131 ms
57,248 KB
testcase_09 AC 133 ms
57,264 KB
testcase_10 AC 129 ms
57,280 KB
testcase_11 AC 131 ms
57,304 KB
testcase_12 AC 134 ms
57,288 KB
testcase_13 AC 130 ms
57,672 KB
testcase_14 AC 136 ms
57,628 KB
testcase_15 AC 136 ms
57,284 KB
testcase_16 AC 133 ms
57,252 KB
testcase_17 AC 136 ms
57,232 KB
testcase_18 AC 129 ms
57,244 KB
testcase_19 AC 133 ms
57,244 KB
testcase_20 AC 127 ms
57,280 KB
testcase_21 AC 132 ms
57,252 KB
testcase_22 AC 137 ms
57,300 KB
testcase_23 AC 129 ms
57,196 KB
testcase_24 AC 130 ms
57,272 KB
testcase_25 AC 136 ms
57,308 KB
testcase_26 AC 130 ms
57,284 KB
testcase_27 AC 134 ms
57,276 KB
testcase_28 AC 132 ms
55,792 KB
testcase_29 AC 135 ms
57,284 KB
testcase_30 AC 134 ms
57,604 KB
testcase_31 AC 127 ms
57,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int a = S.indexOf("c");
        int min = Integer.MAX_VALUE;
        while(a!=-1){
            S = S.substring(a+1);
            int b = S.indexOf("w");
            String t = S.substring(b+1);
            int c = t.indexOf("w");
            if(c!=-1 && min>b+c+3){
                min = b+c+3;
            }
            a = S.indexOf("c");
        }
        if(min==Integer.MAX_VALUE){
            System.out.println(-1);
        }else{
            System.out.println(min);
        }
    }
}
0