結果

問題 No.345 最小チワワ問題
ユーザー ぴろずぴろず
提出日時 2016-02-26 22:24:35
言語 Java19
(openjdk 21)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 716 bytes
コンパイル時間 3,130 ms
コンパイル使用メモリ 74,900 KB
実行使用メモリ 57,592 KB
最終ジャッジ日時 2023-10-26 03:27:56
合計ジャッジ時間 7,784 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
57,448 KB
testcase_01 AC 124 ms
57,344 KB
testcase_02 AC 124 ms
57,424 KB
testcase_03 AC 123 ms
57,512 KB
testcase_04 AC 125 ms
57,432 KB
testcase_05 AC 124 ms
57,424 KB
testcase_06 AC 126 ms
57,204 KB
testcase_07 AC 125 ms
57,468 KB
testcase_08 AC 122 ms
57,536 KB
testcase_09 AC 124 ms
57,544 KB
testcase_10 AC 119 ms
56,776 KB
testcase_11 AC 127 ms
57,500 KB
testcase_12 AC 141 ms
57,476 KB
testcase_13 AC 135 ms
57,420 KB
testcase_14 AC 146 ms
57,392 KB
testcase_15 AC 128 ms
57,176 KB
testcase_16 AC 125 ms
57,468 KB
testcase_17 AC 123 ms
57,220 KB
testcase_18 AC 131 ms
57,436 KB
testcase_19 AC 130 ms
57,512 KB
testcase_20 AC 125 ms
57,592 KB
testcase_21 AC 127 ms
57,216 KB
testcase_22 AC 125 ms
57,424 KB
testcase_23 AC 128 ms
57,196 KB
testcase_24 AC 122 ms
57,480 KB
testcase_25 AC 124 ms
57,180 KB
testcase_26 AC 123 ms
57,400 KB
testcase_27 AC 128 ms
57,344 KB
testcase_28 AC 125 ms
57,384 KB
testcase_29 AC 127 ms
57,464 KB
testcase_30 AC 130 ms
57,456 KB
testcase_31 AC 125 ms
57,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no345;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		int min = Integer.MAX_VALUE;
		for(int i=0;i<n;i++) {
			for(int j=i;j<n;j++) {
				String t = s.substring(i, j + 1);
				if (isChiwawaSequence(t)) {
					min = Math.min(min, j - i + 1);
				}
			}
		}
		System.out.println(min == Integer.MAX_VALUE ? -1 : min);
	}
	
	public static boolean isChiwawaSequence(String s) {
		int state = 0;
		for(int i=0;i<s.length();i++) {
			if (state == 0 && s.charAt(i) == 'c') {
				state++;
			}else if(state >= 1 && s.charAt(i) == 'w') {
				state++;
			}
		}
		return state >= 3;
	}

}
0