結果

問題 No.345 最小チワワ問題
ユーザー TwinkleStar74TwinkleStar74
提出日時 2017-09-23 11:19:57
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,044 bytes
コンパイル時間 2,735 ms
コンパイル使用メモリ 78,060 KB
実行使用メモリ 50,488 KB
最終ジャッジ日時 2024-04-26 15:22:00
合計ジャッジ時間 5,566 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
50,076 KB
testcase_01 AC 52 ms
50,204 KB
testcase_02 AC 50 ms
50,220 KB
testcase_03 AC 52 ms
49,916 KB
testcase_04 AC 50 ms
50,080 KB
testcase_05 AC 51 ms
50,244 KB
testcase_06 AC 52 ms
49,868 KB
testcase_07 AC 51 ms
50,144 KB
testcase_08 AC 51 ms
50,100 KB
testcase_09 AC 51 ms
49,940 KB
testcase_10 AC 51 ms
49,880 KB
testcase_11 AC 51 ms
50,224 KB
testcase_12 RE -
testcase_13 AC 53 ms
50,376 KB
testcase_14 AC 52 ms
50,028 KB
testcase_15 AC 51 ms
49,900 KB
testcase_16 AC 51 ms
50,136 KB
testcase_17 AC 50 ms
50,180 KB
testcase_18 AC 52 ms
50,156 KB
testcase_19 AC 53 ms
50,208 KB
testcase_20 AC 51 ms
50,032 KB
testcase_21 AC 52 ms
49,836 KB
testcase_22 AC 51 ms
49,892 KB
testcase_23 AC 51 ms
50,172 KB
testcase_24 AC 51 ms
50,088 KB
testcase_25 AC 52 ms
50,320 KB
testcase_26 AC 52 ms
50,224 KB
testcase_27 AC 52 ms
50,252 KB
testcase_28 AC 52 ms
50,100 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class No345 {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		
		int [] C = new int[str.length()];
		Arrays.fill(C,0); 
		C[0] = str.indexOf("c");
		
		int [] length = new int[str.length()];
		Arrays.fill(length,-1); 
		
		for (int i=0; i<str.length(); i++){
			C[i+1] = str.indexOf("c",C[i]+1);  //次のcを探す位置は直前のcの位置+1から
			if(C[i] != -1){
				int W1 = str.indexOf("w",C[i]+1);  //1つめのwは直前のcの位置+1から
				int W2 = str.indexOf("w",W1+1);  //2つめのwは直前のwの位置+1から
				if(W1 != -1 && W2 != -1) length[i] = W2 - C[i] + 1; //c,w,wがあれば
			}
			else break;
		}
		int ans = length[0];
		for (int i = 1; i< length.length; i++){
			if (length[i] != -1 && length[i-1] > length[i]) ans = length[i];
		}
		System.out.println(ans);
	}
}
0