結果

問題 No.345 最小チワワ問題
ユーザー matsuyoshi30matsuyoshi30
提出日時 2017-01-26 22:29:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 2,731 ms
コンパイル使用メモリ 76,064 KB
実行使用メモリ 57,620 KB
最終ジャッジ日時 2023-10-26 04:06:02
合計ジャッジ時間 7,654 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
57,520 KB
testcase_01 AC 128 ms
57,304 KB
testcase_02 AC 132 ms
57,252 KB
testcase_03 AC 130 ms
57,292 KB
testcase_04 AC 134 ms
57,532 KB
testcase_05 AC 130 ms
57,288 KB
testcase_06 AC 127 ms
57,308 KB
testcase_07 AC 132 ms
57,296 KB
testcase_08 AC 133 ms
57,520 KB
testcase_09 AC 132 ms
57,280 KB
testcase_10 AC 139 ms
57,284 KB
testcase_11 AC 132 ms
57,288 KB
testcase_12 AC 145 ms
57,272 KB
testcase_13 AC 142 ms
57,248 KB
testcase_14 AC 146 ms
57,340 KB
testcase_15 AC 133 ms
57,232 KB
testcase_16 AC 128 ms
57,248 KB
testcase_17 AC 129 ms
57,308 KB
testcase_18 AC 134 ms
57,284 KB
testcase_19 AC 129 ms
57,348 KB
testcase_20 AC 135 ms
57,364 KB
testcase_21 AC 136 ms
57,224 KB
testcase_22 AC 130 ms
57,488 KB
testcase_23 AC 128 ms
57,520 KB
testcase_24 AC 141 ms
57,340 KB
testcase_25 AC 131 ms
57,284 KB
testcase_26 AC 125 ms
57,196 KB
testcase_27 AC 126 ms
57,208 KB
testcase_28 AC 128 ms
57,512 KB
testcase_29 AC 131 ms
57,312 KB
testcase_30 AC 129 ms
57,620 KB
testcase_31 AC 128 ms
57,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

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

        int ans = Integer.MAX_VALUE;

        for(int i=0; i<s.length(); i++) {
            for(int j=i+1; j<s.length(); j++) {
                for(int k=j+1; k<s.length(); k++) {
                    if(s.charAt(i) == 'c' && s.charAt(j) == 'w' && s.charAt(k) == 'w') {
                        ans = Math.min(ans, k-i+1);
                    }
                }
            }
        }

        if(ans == Integer.MAX_VALUE) ans = -1;

        System.out.println(ans);

        in.close();
    }
}
0