結果

問題 No.345 最小チワワ問題
ユーザー h_tyokinuhatah_tyokinuhata
提出日時 2016-02-27 22:58:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 777 bytes
コンパイル時間 4,126 ms
コンパイル使用メモリ 74,260 KB
実行使用メモリ 57,796 KB
最終ジャッジ日時 2023-10-24 18:41:43
合計ジャッジ時間 6,413 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
57,348 KB
testcase_01 AC 113 ms
57,292 KB
testcase_02 AC 102 ms
55,928 KB
testcase_03 AC 106 ms
56,796 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 102 ms
55,916 KB
testcase_08 AC 106 ms
56,284 KB
testcase_09 AC 116 ms
57,112 KB
testcase_10 AC 117 ms
57,712 KB
testcase_11 AC 113 ms
56,248 KB
testcase_12 AC 106 ms
56,288 KB
testcase_13 AC 114 ms
57,324 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 119 ms
57,456 KB
testcase_18 WA -
testcase_19 AC 105 ms
56,136 KB
testcase_20 AC 103 ms
56,200 KB
testcase_21 AC 112 ms
57,220 KB
testcase_22 AC 108 ms
56,016 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 115 ms
57,396 KB
testcase_28 AC 113 ms
57,396 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 111 ms
55,408 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] == '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