結果

問題 No.345 最小チワワ問題
ユーザー GrenacheGrenache
提出日時 2016-02-26 22:26:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 3,700 ms
コンパイル使用メモリ 74,496 KB
実行使用メモリ 57,760 KB
最終ジャッジ日時 2023-10-26 03:28:34
合計ジャッジ時間 8,962 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
57,616 KB
testcase_01 AC 130 ms
57,272 KB
testcase_02 AC 134 ms
57,296 KB
testcase_03 AC 133 ms
57,516 KB
testcase_04 AC 134 ms
57,288 KB
testcase_05 AC 135 ms
55,524 KB
testcase_06 AC 128 ms
57,564 KB
testcase_07 AC 134 ms
57,556 KB
testcase_08 AC 136 ms
57,244 KB
testcase_09 AC 134 ms
57,292 KB
testcase_10 AC 129 ms
57,268 KB
testcase_11 AC 131 ms
57,272 KB
testcase_12 AC 131 ms
57,544 KB
testcase_13 AC 127 ms
57,300 KB
testcase_14 AC 128 ms
57,516 KB
testcase_15 AC 128 ms
57,524 KB
testcase_16 AC 126 ms
57,292 KB
testcase_17 AC 129 ms
57,284 KB
testcase_18 AC 130 ms
57,760 KB
testcase_19 AC 131 ms
57,284 KB
testcase_20 AC 128 ms
57,244 KB
testcase_21 AC 127 ms
57,228 KB
testcase_22 AC 128 ms
57,496 KB
testcase_23 AC 127 ms
57,692 KB
testcase_24 AC 125 ms
57,444 KB
testcase_25 AC 127 ms
57,608 KB
testcase_26 AC 126 ms
57,572 KB
testcase_27 AC 128 ms
57,284 KB
testcase_28 AC 131 ms
57,508 KB
testcase_29 AC 130 ms
57,692 KB
testcase_30 AC 131 ms
57,240 KB
testcase_31 AC 133 ms
57,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder345 {

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

        char[] s = sc.next().toCharArray();
        int n = s.length;

        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
        	if (s[i] != 'c') {
        		continue;
        	} else {
        		int cnt = 0;
        		int j;
        		for (j = i + 1; j < n && cnt < 2; j++) {
        			if (s[j] == 'w') {
        				cnt++;
        			}
        		}

        		if (cnt == 2) {
        			min = Math.min(min, j - i);
        		}
        	}
        }

        if (min == Integer.MAX_VALUE) {
        	System.out.println(-1);
        } else {
        	System.out.println(min);
        }

        sc.close();
    }
}
0