結果

問題 No.345 最小チワワ問題
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-10 15:47:57
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 676 bytes
コンパイル時間 2,268 ms
コンパイル使用メモリ 74,596 KB
実行使用メモリ 41,720 KB
最終ジャッジ日時 2024-04-22 14:37:24
合計ジャッジ時間 7,905 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
41,388 KB
testcase_01 AC 121 ms
41,060 KB
testcase_02 AC 109 ms
40,200 KB
testcase_03 AC 123 ms
40,952 KB
testcase_04 AC 123 ms
40,976 KB
testcase_05 WA -
testcase_06 AC 110 ms
39,840 KB
testcase_07 AC 110 ms
40,120 KB
testcase_08 AC 125 ms
41,588 KB
testcase_09 AC 123 ms
41,140 KB
testcase_10 AC 108 ms
39,984 KB
testcase_11 AC 122 ms
41,120 KB
testcase_12 AC 110 ms
40,052 KB
testcase_13 AC 123 ms
41,376 KB
testcase_14 AC 125 ms
41,328 KB
testcase_15 AC 128 ms
41,276 KB
testcase_16 AC 109 ms
40,028 KB
testcase_17 AC 110 ms
39,984 KB
testcase_18 WA -
testcase_19 AC 125 ms
41,144 KB
testcase_20 AC 122 ms
40,804 KB
testcase_21 AC 108 ms
40,200 KB
testcase_22 AC 127 ms
41,320 KB
testcase_23 AC 110 ms
39,852 KB
testcase_24 AC 124 ms
41,416 KB
testcase_25 AC 109 ms
39,868 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 125 ms
41,592 KB
testcase_29 AC 123 ms
41,188 KB
testcase_30 AC 120 ms
41,104 KB
testcase_31 AC 120 ms
40,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		String s = sc.next();
		String status = "";
		int min = 1000;
		int len = 0;
		for (int i=0; i<s.length(); i++) {
			char c = s.charAt(i);
			if (status.equals("")) {
				if (c=='c') {status = "c"; len = 1;}
			}
			else if (status.equals("c")) {
				if (c=='c') {len = 1;}
				else if (c=='w') {status = "cw"; len++;}
				else {len++;}
			}
			else if (status.equals("cw")) {
				if (c=='w') {
					len++;
					min = Math.min(min,len);
					status = "";
					len = 0;
				}
				else {len++;}
			}
		}
		System.out.println(min==1000?-1:min);
	}
}
0