結果

問題 No.345 最小チワワ問題
ユーザー ohagi_1182ohagi_1182
提出日時 2017-10-13 20:41:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 476 bytes
コンパイル時間 3,652 ms
コンパイル使用メモリ 74,408 KB
実行使用メモリ 57,592 KB
最終ジャッジ日時 2023-10-26 04:17:14
合計ジャッジ時間 7,065 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
57,324 KB
testcase_01 AC 114 ms
57,244 KB
testcase_02 AC 117 ms
57,332 KB
testcase_03 AC 120 ms
57,272 KB
testcase_04 AC 116 ms
55,656 KB
testcase_05 AC 141 ms
57,592 KB
testcase_06 AC 116 ms
57,540 KB
testcase_07 AC 115 ms
57,276 KB
testcase_08 AC 106 ms
56,300 KB
testcase_09 AC 105 ms
56,308 KB
testcase_10 AC 115 ms
57,332 KB
testcase_11 AC 136 ms
57,540 KB
testcase_12 AC 106 ms
56,276 KB
testcase_13 AC 106 ms
56,300 KB
testcase_14 AC 116 ms
57,324 KB
testcase_15 AC 114 ms
57,292 KB
testcase_16 AC 115 ms
57,352 KB
testcase_17 AC 116 ms
55,552 KB
testcase_18 AC 114 ms
57,336 KB
testcase_19 AC 117 ms
57,540 KB
testcase_20 AC 114 ms
57,316 KB
testcase_21 AC 117 ms
57,244 KB
testcase_22 AC 115 ms
57,344 KB
testcase_23 AC 118 ms
57,340 KB
testcase_24 AC 116 ms
57,292 KB
testcase_25 AC 115 ms
57,308 KB
testcase_26 AC 111 ms
57,304 KB
testcase_27 AC 116 ms
57,288 KB
testcase_28 AC 116 ms
57,316 KB
testcase_29 AC 114 ms
57,292 KB
testcase_30 AC 104 ms
56,280 KB
testcase_31 AC 112 ms
57,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

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