結果

問題 No.345 最小チワワ問題
ユーザー h_tyokinuhatah_tyokinuhata
提出日時 2016-02-27 23:08:29
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 933 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 77,436 KB
実行使用メモリ 57,564 KB
最終ジャッジ日時 2023-10-24 18:41:20
合計ジャッジ時間 6,538 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
56,216 KB
testcase_01 AC 128 ms
57,004 KB
testcase_02 AC 113 ms
57,436 KB
testcase_03 AC 114 ms
57,564 KB
testcase_04 AC 115 ms
57,420 KB
testcase_05 WA -
testcase_06 AC 114 ms
57,284 KB
testcase_07 AC 113 ms
57,436 KB
testcase_08 AC 103 ms
56,172 KB
testcase_09 AC 107 ms
56,804 KB
testcase_10 AC 113 ms
57,464 KB
testcase_11 AC 104 ms
55,952 KB
testcase_12 AC 114 ms
57,180 KB
testcase_13 AC 116 ms
57,348 KB
testcase_14 AC 104 ms
55,916 KB
testcase_15 AC 114 ms
57,372 KB
testcase_16 AC 113 ms
57,420 KB
testcase_17 AC 113 ms
57,224 KB
testcase_18 WA -
testcase_19 AC 103 ms
55,932 KB
testcase_20 AC 115 ms
57,500 KB
testcase_21 AC 115 ms
57,364 KB
testcase_22 AC 105 ms
56,196 KB
testcase_23 AC 118 ms
57,128 KB
testcase_24 AC 113 ms
57,188 KB
testcase_25 AC 115 ms
57,424 KB
testcase_26 WA -
testcase_27 AC 113 ms
57,240 KB
testcase_28 AC 114 ms
57,384 KB
testcase_29 AC 112 ms
57,276 KB
testcase_30 WA -
testcase_31 AC 115 ms
57,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String S = sc.next();
		
		char[] charS = S.toCharArray();
		
		int i = 0, cnt = 0, flag = 0, cflag = 0, min = Integer.MAX_VALUE;
		
		while(i < charS.length) {
			if(charS[i] == 'c') {
				for(int j = i + 1; j < charS.length; j++) {
					if(charS[j] == 'c' && cflag == 0) {
						i = j;
					}
					if(charS[j] == 'w') {
						cnt++;
						
						if(cnt == 1) {
							cflag = 1;
						}
						
						if(cnt == 2) {
							if(j - i + 1 < min) {
								min = j - i + 1;
								charS = S.substring(j + 1).toCharArray();
								flag = 1;
							}
						} 
					}
				}
			}
		
			if(flag == 1) {
				i = 0;
				cnt = 0;
				cflag = 0;
				flag = 0;
			} else {
				cflag = 0;
				i++;
			}
		}
		
		if(min == Integer.MAX_VALUE) {
			System.out.println(-1);	
		} else {
			System.out.println(min);
		}
	}
}
0