結果

問題 No.345 最小チワワ問題
ユーザー YukimotoPGYukimotoPG
提出日時 2019-02-14 16:35:36
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 753 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 73,080 KB
実行使用メモリ 56,284 KB
最終ジャッジ日時 2023-10-11 12:40:58
合計ジャッジ時間 7,223 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
56,040 KB
testcase_01 AC 115 ms
53,820 KB
testcase_02 AC 117 ms
55,668 KB
testcase_03 AC 117 ms
55,688 KB
testcase_04 AC 116 ms
56,044 KB
testcase_05 WA -
testcase_06 AC 118 ms
55,672 KB
testcase_07 AC 117 ms
56,284 KB
testcase_08 AC 117 ms
55,724 KB
testcase_09 AC 119 ms
55,220 KB
testcase_10 AC 116 ms
56,164 KB
testcase_11 AC 116 ms
55,444 KB
testcase_12 AC 115 ms
55,744 KB
testcase_13 AC 117 ms
55,752 KB
testcase_14 AC 116 ms
55,356 KB
testcase_15 AC 116 ms
55,648 KB
testcase_16 AC 116 ms
55,824 KB
testcase_17 AC 118 ms
56,092 KB
testcase_18 WA -
testcase_19 AC 116 ms
55,684 KB
testcase_20 AC 119 ms
56,012 KB
testcase_21 AC 116 ms
55,852 KB
testcase_22 AC 116 ms
55,792 KB
testcase_23 AC 118 ms
55,888 KB
testcase_24 AC 119 ms
55,504 KB
testcase_25 AC 116 ms
55,956 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 116 ms
55,792 KB
testcase_29 AC 116 ms
56,100 KB
testcase_30 AC 117 ms
55,972 KB
testcase_31 AC 120 ms
55,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		String s = sc.next();
		
		String mode = "c";
		int min = Integer.MAX_VALUE;
		
		int L = -1; int R = -1;
		
		
		for (int i=0; i<s.length(); i++) {
			if (mode.equals("c")) {
				if (s.charAt(i) == 'c') {
					L = i;
					mode = "w";
				}
			}
			else if (mode.equals("w")) {
				if (s.charAt(i) == 'w') {
					mode = "ww";
				}
				else if (s.charAt(i) == 'c') {
					L = i;
				}
			}
			else if (mode.equals("ww")) {
				if (s.charAt(i) == 'w') {
					R = i;
					min = Math.min(min, R-L+1);
					mode = "c";
				}
			}
//			System.out.println(L+":"+R);
		}
		
		System.out.println(min==Integer.MAX_VALUE?-1:min);
		
	}
}
0