結果

問題 No.345 最小チワワ問題
ユーザー ohagi_1182ohagi_1182
提出日時 2017-11-24 22:17:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 573 bytes
コンパイル時間 2,086 ms
コンパイル使用メモリ 71,952 KB
実行使用メモリ 58,180 KB
最終ジャッジ日時 2023-08-18 04:30:59
合計ジャッジ時間 7,877 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 118 ms
55,420 KB
testcase_08 AC 118 ms
55,664 KB
testcase_09 AC 122 ms
55,620 KB
testcase_10 WA -
testcase_11 AC 124 ms
55,508 KB
testcase_12 AC 134 ms
55,680 KB
testcase_13 AC 130 ms
55,800 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 120 ms
55,420 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 120 ms
55,680 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 121 ms
56,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	static final int INF = Integer.MAX_VALUE;

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