結果

問題 No.345 最小チワワ問題
ユーザー ohagi_1182ohagi_1182
提出日時 2017-10-13 21:11:42
言語 Java19
(openjdk 21)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 464 bytes
コンパイル時間 2,334 ms
コンパイル使用メモリ 74,988 KB
実行使用メモリ 57,840 KB
最終ジャッジ日時 2023-10-26 04:20:21
合計ジャッジ時間 7,854 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
57,136 KB
testcase_01 AC 136 ms
57,504 KB
testcase_02 AC 136 ms
57,568 KB
testcase_03 AC 135 ms
57,336 KB
testcase_04 AC 134 ms
57,324 KB
testcase_05 AC 135 ms
57,572 KB
testcase_06 AC 133 ms
57,332 KB
testcase_07 AC 134 ms
57,300 KB
testcase_08 AC 135 ms
57,172 KB
testcase_09 AC 133 ms
57,312 KB
testcase_10 AC 129 ms
57,340 KB
testcase_11 AC 132 ms
57,300 KB
testcase_12 AC 134 ms
57,484 KB
testcase_13 AC 136 ms
57,188 KB
testcase_14 AC 135 ms
57,840 KB
testcase_15 AC 137 ms
57,172 KB
testcase_16 AC 135 ms
57,300 KB
testcase_17 AC 134 ms
57,420 KB
testcase_18 AC 135 ms
57,420 KB
testcase_19 AC 133 ms
57,428 KB
testcase_20 AC 137 ms
57,212 KB
testcase_21 AC 135 ms
57,380 KB
testcase_22 AC 135 ms
57,280 KB
testcase_23 AC 139 ms
55,272 KB
testcase_24 AC 134 ms
57,524 KB
testcase_25 AC 132 ms
55,256 KB
testcase_26 AC 135 ms
57,568 KB
testcase_27 AC 135 ms
57,580 KB
testcase_28 AC 135 ms
57,336 KB
testcase_29 AC 135 ms
57,348 KB
testcase_30 AC 135 ms
57,336 KB
testcase_31 AC 133 ms
57,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		int ans = 1001001001;
		int w1 = n; int w2 = n;
		for(int i = n - 1 ; i >= 0 ; i--) {
			if(s.charAt(i) == 'w') {
				w2 = w1;
				w1 = i;
			} else if(s.charAt(i) == 'c' && w2 != n){
				ans = Math.min(ans, w2 - i + 1);
			}
		}
		System.out.println(ans == 1001001001 ? -1 : ans);
	}
}
0