結果

問題 No.345 最小チワワ問題
ユーザー nglkrianbrjfnglkrianbrjf
提出日時 2016-02-27 00:01:21
言語 Java21
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,083 bytes
コンパイル時間 3,474 ms
コンパイル使用メモリ 76,880 KB
実行使用メモリ 37,616 KB
最終ジャッジ日時 2024-04-17 22:50:42
合計ジャッジ時間 5,450 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
36,972 KB
testcase_01 AC 48 ms
37,616 KB
testcase_02 AC 49 ms
37,448 KB
testcase_03 AC 48 ms
37,416 KB
testcase_04 AC 49 ms
37,300 KB
testcase_05 AC 50 ms
36,908 KB
testcase_06 AC 47 ms
37,308 KB
testcase_07 AC 52 ms
37,448 KB
testcase_08 AC 50 ms
37,560 KB
testcase_09 AC 49 ms
37,224 KB
testcase_10 AC 46 ms
37,288 KB
testcase_11 AC 48 ms
37,332 KB
testcase_12 AC 47 ms
37,428 KB
testcase_13 AC 47 ms
37,372 KB
testcase_14 AC 50 ms
37,484 KB
testcase_15 AC 47 ms
37,412 KB
testcase_16 AC 49 ms
37,268 KB
testcase_17 AC 48 ms
37,480 KB
testcase_18 AC 46 ms
37,572 KB
testcase_19 AC 49 ms
37,284 KB
testcase_20 AC 51 ms
37,460 KB
testcase_21 AC 54 ms
37,472 KB
testcase_22 AC 48 ms
37,408 KB
testcase_23 AC 47 ms
37,468 KB
testcase_24 AC 48 ms
37,484 KB
testcase_25 AC 51 ms
37,196 KB
testcase_26 AC 47 ms
37,204 KB
testcase_27 AC 49 ms
37,520 KB
testcase_28 WA -
testcase_29 AC 49 ms
37,288 KB
testcase_30 AC 46 ms
37,568 KB
testcase_31 AC 51 ms
37,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class QuestionA {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line;

		try{
			line = in.readLine();
		}catch(IOException e){
			System.out.println("-1");
			return;
		}

		int[] c = new int[100000];
		Arrays.fill(c, 0);

		int min = line.length();
		int ccount = 0;//直前のcの位置
		int w = 0;//直前のwの位置
		boolean check = false;
		int max = line.length();

		for(int i = 0; i < max; i++){
			char chiwawa =line.charAt(i);
			if(chiwawa == 'c'){
				c[ccount]= i;
				ccount++;
			}
			if(chiwawa == 'w'){
				if(w > 0 && ccount > 0){
					check = true;
					for(int j = 0; j < ccount; j++){
						if(c[j] < w && min > i - c[j] + 1){
							min = i - c[j] + 1;
						}
					}
					w = i;
				}
				else
					w = i;
			}
		}

		if(check) System.out.println(min);
		else System.out.println("-1");
	}

}
0