結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
57,384 KB
testcase_01 AC 116 ms
57,404 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 119 ms
55,612 KB
testcase_05 WA -
testcase_06 AC 106 ms
56,144 KB
testcase_07 AC 119 ms
55,496 KB
testcase_08 AC 114 ms
57,516 KB
testcase_09 AC 103 ms
55,696 KB
testcase_10 AC 121 ms
57,184 KB
testcase_11 AC 113 ms
57,260 KB
testcase_12 AC 119 ms
57,456 KB
testcase_13 AC 114 ms
57,276 KB
testcase_14 AC 105 ms
56,208 KB
testcase_15 AC 115 ms
57,440 KB
testcase_16 AC 114 ms
57,256 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 112 ms
57,244 KB
testcase_20 AC 114 ms
57,500 KB
testcase_21 AC 114 ms
57,396 KB
testcase_22 AC 119 ms
57,116 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 112 ms
57,156 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 116 ms
57,360 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, 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') {
						i = j;
					}
					if(charS[j] == 'w') {
						cnt++;
						
						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;
				flag = 0;
			} else {
				i++;
			}
		}
		
		if(min == Integer.MAX_VALUE) {
			System.out.println(-1);	
		} else {
			System.out.println(min);
		}
	}
}
0