結果

問題 No.345 最小チワワ問題
ユーザー ohagi_1182ohagi_1182
提出日時 2017-10-13 18:49:56
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 588 bytes
コンパイル時間 2,171 ms
コンパイル使用メモリ 74,264 KB
実行使用メモリ 41,600 KB
最終ジャッジ日時 2024-04-28 17:33:26
合計ジャッジ時間 7,120 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
41,304 KB
testcase_01 AC 127 ms
41,180 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 126 ms
41,132 KB
testcase_08 AC 123 ms
40,952 KB
testcase_09 AC 111 ms
40,108 KB
testcase_10 AC 128 ms
41,040 KB
testcase_11 AC 130 ms
41,360 KB
testcase_12 AC 124 ms
41,048 KB
testcase_13 AC 126 ms
41,080 KB
testcase_14 WA -
testcase_15 AC 122 ms
41,340 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 121 ms
41,128 KB
testcase_20 AC 122 ms
40,828 KB
testcase_21 AC 128 ms
41,120 KB
testcase_22 AC 121 ms
40,976 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 107 ms
40,060 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 121 ms
41,080 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 c = 0; int w = 0; int indexC = 0; int indexW = 0; int ans = 1001001001;
		for(int i = 0 ; i < s.length() ; i++) {
			if(s.charAt(i) == 'c') {
				c++;
				w = 0;
				indexC = i;
			} else if(s.charAt(i) == 'w') {
				w++;
				if(c == 1 && w == 2) {
					indexW = i;
					ans = Math.min(ans, indexW - indexC + 1);
				}
			}
		}
		if(ans != 1001001001) {
			System.out.println(ans);
		} else {
			System.out.println(-1);
		}
	}
}
0