結果

問題 No.345 最小チワワ問題
ユーザー fkwnw3_1243fkwnw3_1243
提出日時 2017-05-05 08:57:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,185 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 75,460 KB
実行使用メモリ 53,332 KB
最終ジャッジ日時 2023-10-26 04:10:29
合計ジャッジ時間 5,003 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
52,196 KB
testcase_01 AC 56 ms
52,352 KB
testcase_02 AC 56 ms
53,332 KB
testcase_03 AC 55 ms
53,316 KB
testcase_04 AC 56 ms
53,324 KB
testcase_05 AC 54 ms
53,320 KB
testcase_06 AC 54 ms
53,316 KB
testcase_07 AC 54 ms
53,316 KB
testcase_08 AC 54 ms
53,316 KB
testcase_09 AC 54 ms
53,316 KB
testcase_10 AC 54 ms
53,320 KB
testcase_11 AC 55 ms
53,324 KB
testcase_12 AC 54 ms
53,316 KB
testcase_13 AC 56 ms
53,316 KB
testcase_14 AC 54 ms
53,320 KB
testcase_15 AC 55 ms
53,332 KB
testcase_16 AC 55 ms
53,320 KB
testcase_17 AC 55 ms
53,328 KB
testcase_18 AC 55 ms
52,320 KB
testcase_19 AC 62 ms
53,316 KB
testcase_20 AC 53 ms
51,272 KB
testcase_21 AC 55 ms
53,328 KB
testcase_22 AC 56 ms
53,316 KB
testcase_23 AC 54 ms
52,312 KB
testcase_24 AC 56 ms
52,188 KB
testcase_25 AC 54 ms
53,316 KB
testcase_26 AC 57 ms
52,288 KB
testcase_27 AC 54 ms
53,320 KB
testcase_28 AC 54 ms
53,312 KB
testcase_29 AC 54 ms
53,320 KB
testcase_30 AC 56 ms
53,320 KB
testcase_31 AC 56 ms
53,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import static java.lang.System.in;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String S = reader.readLine();
        int wCount = 0;
        int firstW = 0;
        int secondW = 0;
        int answer = Integer.MAX_VALUE;
        boolean found = false;
        for (int i = S.length() - 1; i >= 0; i--) {
            char current = S.charAt(i);
            if (current == 'w') {
                wCount += 1;
                if (wCount == 1) {
                    firstW = i;
                } else if (wCount == 2) {
                    secondW = i;
                } else {
                    firstW = secondW;
                    secondW = i;
                }
            } else if (current == 'c' && wCount >= 2) {
                answer = Math.min(answer, firstW - i + 1);
                found = true;
            }
        }
        if(found) {
            System.out.println(answer);
        } else {
            System.out.println(-1);
        }
    }
}
0