結果

問題 No.345 最小チワワ問題
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-10 15:44:26
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 732 bytes
コンパイル時間 4,116 ms
コンパイル使用メモリ 75,096 KB
実行使用メモリ 56,260 KB
最終ジャッジ日時 2024-04-22 14:31:51
合計ジャッジ時間 9,397 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
41,184 KB
testcase_01 AC 128 ms
41,272 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 127 ms
41,576 KB
testcase_08 AC 129 ms
41,044 KB
testcase_09 AC 130 ms
41,412 KB
testcase_10 AC 130 ms
41,300 KB
testcase_11 AC 129 ms
41,296 KB
testcase_12 AC 131 ms
41,136 KB
testcase_13 AC 129 ms
41,172 KB
testcase_14 WA -
testcase_15 AC 132 ms
41,292 KB
testcase_16 AC 130 ms
41,264 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 128 ms
41,432 KB
testcase_20 AC 129 ms
41,576 KB
testcase_21 AC 128 ms
41,160 KB
testcase_22 AC 131 ms
41,268 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 130 ms
41,528 KB
testcase_29 AC 131 ms
41,404 KB
testcase_30 WA -
testcase_31 AC 117 ms
39,988 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++;}
			}
			else if (status.equals("c")) {
				if (c=='c') {status = ""; len = 0;}
				else if (c=='w') {status = "cw"; len++;}
				else {len++;}
			}
			else if (status.equals("cw")) {
				if (c=='c') {status = ""; len = 0;}
				else if (c=='w') {
					len++;
					min = Math.min(min,len);
					status = "";
					len = 0;
				}
				else {len++;}
			}
		}
		System.out.println(min==1000?-1:min);
	}
}
0