結果

問題 No.345 最小チワワ問題
ユーザー YukimotoPGYukimotoPG
提出日時 2019-02-14 16:34:03
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 700 bytes
コンパイル時間 2,262 ms
コンパイル使用メモリ 71,968 KB
実行使用メモリ 58,240 KB
最終ジャッジ日時 2023-10-11 12:40:42
合計ジャッジ時間 8,077 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,760 KB
testcase_01 AC 120 ms
55,720 KB
testcase_02 AC 119 ms
55,552 KB
testcase_03 AC 119 ms
55,636 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 117 ms
55,640 KB
testcase_08 AC 118 ms
53,576 KB
testcase_09 AC 119 ms
55,760 KB
testcase_10 AC 118 ms
55,796 KB
testcase_11 AC 119 ms
55,400 KB
testcase_12 AC 120 ms
56,048 KB
testcase_13 AC 118 ms
56,088 KB
testcase_14 WA -
testcase_15 AC 118 ms
55,776 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 120 ms
55,840 KB
testcase_20 AC 116 ms
55,388 KB
testcase_21 AC 118 ms
55,904 KB
testcase_22 AC 118 ms
55,800 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 121 ms
55,852 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 120 ms
55,968 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 (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