結果

問題 No.345 最小チワワ問題
ユーザー crazybbb3crazybbb3
提出日時 2017-01-31 21:15:18
言語 Java19
(openjdk 21)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,579 bytes
コンパイル時間 2,312 ms
コンパイル使用メモリ 77,664 KB
実行使用メモリ 53,472 KB
最終ジャッジ日時 2023-10-26 04:06:08
合計ジャッジ時間 5,225 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
53,436 KB
testcase_01 AC 56 ms
53,440 KB
testcase_02 AC 58 ms
52,376 KB
testcase_03 AC 57 ms
52,416 KB
testcase_04 AC 56 ms
53,436 KB
testcase_05 AC 56 ms
53,444 KB
testcase_06 AC 56 ms
53,436 KB
testcase_07 AC 56 ms
53,444 KB
testcase_08 AC 55 ms
53,452 KB
testcase_09 AC 56 ms
53,472 KB
testcase_10 AC 56 ms
53,440 KB
testcase_11 AC 57 ms
52,492 KB
testcase_12 AC 57 ms
53,444 KB
testcase_13 AC 55 ms
53,436 KB
testcase_14 AC 58 ms
53,436 KB
testcase_15 AC 56 ms
52,372 KB
testcase_16 AC 57 ms
53,436 KB
testcase_17 AC 57 ms
51,404 KB
testcase_18 AC 56 ms
53,436 KB
testcase_19 AC 57 ms
53,444 KB
testcase_20 AC 56 ms
53,440 KB
testcase_21 AC 56 ms
53,436 KB
testcase_22 AC 56 ms
53,448 KB
testcase_23 AC 55 ms
52,372 KB
testcase_24 AC 55 ms
53,448 KB
testcase_25 AC 57 ms
51,524 KB
testcase_26 AC 57 ms
52,392 KB
testcase_27 AC 58 ms
52,360 KB
testcase_28 AC 57 ms
52,396 KB
testcase_29 AC 57 ms
53,440 KB
testcase_30 AC 56 ms
53,436 KB
testcase_31 AC 56 ms
53,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    void solve() throws IOException {
        String s = ns();
        int w1 = -1;
        int w2 = -1;
        int ans = Integer.MAX_VALUE;

        for (int i = s.length() - 1; i >= 0; i--) {
            if (s.charAt(i) == 'w') {
                w1 = w2;
                w2 = i;
            } else if (s.charAt(i) == 'c') {
                if (w1 != -1) {
                    ans = Math.min(ans, w1 - i + 1);
                }
            }
        }

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

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}
0