結果

問題 No.345 最小チワワ問題
ユーザー fkwnw3_1243fkwnw3_1243
提出日時 2017-05-05 08:54:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,368 bytes
コンパイル時間 2,327 ms
コンパイル使用メモリ 74,488 KB
実行使用メモリ 53,284 KB
最終ジャッジ日時 2023-10-26 04:09:38
合計ジャッジ時間 5,156 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
52,340 KB
testcase_01 AC 55 ms
53,260 KB
testcase_02 AC 55 ms
53,268 KB
testcase_03 AC 56 ms
51,216 KB
testcase_04 AC 56 ms
53,264 KB
testcase_05 AC 56 ms
52,328 KB
testcase_06 AC 55 ms
53,264 KB
testcase_07 AC 56 ms
53,272 KB
testcase_08 AC 55 ms
53,264 KB
testcase_09 AC 56 ms
53,200 KB
testcase_10 AC 54 ms
52,308 KB
testcase_11 AC 57 ms
53,260 KB
testcase_12 AC 57 ms
52,196 KB
testcase_13 AC 55 ms
52,284 KB
testcase_14 AC 54 ms
52,156 KB
testcase_15 AC 54 ms
53,264 KB
testcase_16 AC 57 ms
52,216 KB
testcase_17 AC 54 ms
53,268 KB
testcase_18 AC 55 ms
53,260 KB
testcase_19 AC 54 ms
53,256 KB
testcase_20 AC 55 ms
53,276 KB
testcase_21 AC 54 ms
53,264 KB
testcase_22 AC 55 ms
53,276 KB
testcase_23 AC 54 ms
53,264 KB
testcase_24 AC 55 ms
52,344 KB
testcase_25 AC 54 ms
53,204 KB
testcase_26 AC 55 ms
53,268 KB
testcase_27 AC 56 ms
53,256 KB
testcase_28 AC 54 ms
53,264 KB
testcase_29 AC 55 ms
53,260 KB
testcase_30 AC 56 ms
53,284 KB
testcase_31 AC 56 ms
51,344 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;
                }

//                System.out.println("first ; " + firstW + " second; " + secondW);
//
            } else if (current == 'c' && wCount >= 2) {
//                System.out.println("c; " + i + "first ; " + firstW + " second; " + secondW);
                answer = Math.min(answer, firstW - i + 1);
                found = true;
            }
        }
        if(found) {
            System.out.println(answer);
        } else {
            System.out.println(-1);
        }


    }
}
0