結果
問題 |
No.345 最小チワワ問題
|
ユーザー |
|
提出日時 | 2017-09-23 11:19:57 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,044 bytes |
コンパイル時間 | 2,272 ms |
コンパイル使用メモリ | 76,996 KB |
実行使用メモリ | 50,648 KB |
最終ジャッジ日時 | 2024-11-14 04:00:27 |
合計ジャッジ時間 | 5,219 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 WA * 2 RE * 2 |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; class No345 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = br.readLine(); int [] C = new int[str.length()]; Arrays.fill(C,0); C[0] = str.indexOf("c"); int [] length = new int[str.length()]; Arrays.fill(length,-1); for (int i=0; i<str.length(); i++){ C[i+1] = str.indexOf("c",C[i]+1); //次のcを探す位置は直前のcの位置+1から if(C[i] != -1){ int W1 = str.indexOf("w",C[i]+1); //1つめのwは直前のcの位置+1から int W2 = str.indexOf("w",W1+1); //2つめのwは直前のwの位置+1から if(W1 != -1 && W2 != -1) length[i] = W2 - C[i] + 1; //c,w,wがあれば } else break; } int ans = length[0]; for (int i = 1; i< length.length; i++){ if (length[i] != -1 && length[i-1] > length[i]) ans = length[i]; } System.out.println(ans); } }