結果
問題 |
No.345 最小チワワ問題
|
ユーザー |
|
提出日時 | 2019-02-14 16:34:03 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 700 bytes |
コンパイル時間 | 2,111 ms |
コンパイル使用メモリ | 75,200 KB |
実行使用メモリ | 54,416 KB |
最終ジャッジ日時 | 2024-09-13 11:27:30 |
合計ジャッジ時間 | 7,278 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 WA * 14 |
ソースコード
import java.util.*; class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { String s = sc.next(); String mode = "c"; int min = Integer.MAX_VALUE; int L = -1; int R = -1; for (int i=0; i<s.length(); i++) { if (mode.equals("c")) { if (s.charAt(i) == 'c') { L = i; mode = "w"; } } else if (mode.equals("w")) { if (s.charAt(i) == 'w') { mode = "ww"; } } else if (mode.equals("ww")) { if (s.charAt(i) == 'w') { R = i; min = Math.min(min, R-L+1); mode = "c"; } } // System.out.println(L+":"+R); } System.out.println(min==Integer.MAX_VALUE?-1:min); } }