結果

問題 No.345 最小チワワ問題
ユーザー YukimotoPGYukimotoPG
提出日時 2019-02-14 16:48:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 496 bytes
コンパイル時間 2,137 ms
コンパイル使用メモリ 74,524 KB
実行使用メモリ 58,084 KB
最終ジャッジ日時 2024-04-08 11:05:36
合計ジャッジ時間 7,322 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
57,952 KB
testcase_01 AC 125 ms
58,084 KB
testcase_02 AC 127 ms
57,948 KB
testcase_03 AC 128 ms
57,820 KB
testcase_04 AC 131 ms
57,908 KB
testcase_05 AC 127 ms
57,840 KB
testcase_06 AC 125 ms
57,820 KB
testcase_07 AC 127 ms
58,064 KB
testcase_08 AC 127 ms
57,700 KB
testcase_09 AC 125 ms
57,832 KB
testcase_10 AC 127 ms
57,956 KB
testcase_11 AC 136 ms
58,068 KB
testcase_12 AC 126 ms
57,832 KB
testcase_13 AC 125 ms
57,912 KB
testcase_14 AC 131 ms
57,676 KB
testcase_15 AC 127 ms
57,844 KB
testcase_16 AC 128 ms
57,960 KB
testcase_17 AC 127 ms
57,936 KB
testcase_18 AC 130 ms
57,956 KB
testcase_19 AC 124 ms
57,932 KB
testcase_20 AC 127 ms
57,960 KB
testcase_21 AC 126 ms
57,812 KB
testcase_22 AC 133 ms
57,944 KB
testcase_23 AC 129 ms
57,852 KB
testcase_24 AC 128 ms
55,984 KB
testcase_25 AC 129 ms
57,948 KB
testcase_26 AC 127 ms
57,964 KB
testcase_27 AC 128 ms
57,944 KB
testcase_28 AC 125 ms
57,836 KB
testcase_29 AC 125 ms
57,964 KB
testcase_30 AC 127 ms
57,696 KB
testcase_31 AC 127 ms
57,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		String s = sc.next();
		
		int min = Integer.MAX_VALUE;
		for (int i=0; i<s.length(); i++) {
			if (s.charAt(i) == 'c') {
				int wNum = 0;
				for (int j=i; j<s.length(); j++) {
					if (s.charAt(j) == 'w') wNum++;
					if (wNum == 2) {
						min = Math.min(min, j-i+1);
						break;
					}
				}
			}
		}
		
		System.out.println(min==Integer.MAX_VALUE?-1:min);
		
	}
}
0