結果
| 問題 |
No.345 最小チワワ問題
|
| コンテスト | |
| ユーザー |
spacia
|
| 提出日時 | 2016-06-02 13:15:10 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,527 bytes |
| コンパイル時間 | 3,153 ms |
| コンパイル使用メモリ | 78,036 KB |
| 実行使用メモリ | 41,824 KB |
| 最終ジャッジ日時 | 2024-10-08 05:26:08 |
| 合計ジャッジ時間 | 7,316 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 15 |
ソースコード
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
String in = sc.nextLine();
System.out.println(searchMinChiwawaLength(in));
sc.close();
}
// 部分文字列のうちチワワ列となるものの最小の長さを求める
public static int searchMinChiwawaLength (String in) {
// 戻り値
int min_chiwawa_str_length = -1;
// 入力文字列中の'c'と'w'の添え字をそれぞれ格納する
ArrayList<Integer> clocate_of_in = new ArrayList<Integer>();
ArrayList<Integer> wlocate_of_in = new ArrayList<Integer>();
for (int i = 0; i < in.length(); i++) {
if (in.charAt(i) == 'c') clocate_of_in.add(i);
if (in.charAt(i) == 'w') wlocate_of_in.add(i);
}
// 入力文字列中に含まれる'c'と'w'の数
int csize = clocate_of_in.size();
int wsize = wlocate_of_in.size();
for (int ci = 0; ci < csize; ci++) {
// 'c'の位置を取得
int clocate = clocate_of_in.get(ci);
// clocateより右にある'w'の数
int wcnt = 0;
for (int wi = 0; wi < wsize; wi++) {
// 'w'の位置を取得
int wlocate = wlocate_of_in.get(wi);
// 'c'より右にある'w'をカウント
if (clocate < wlocate) wcnt++;
// 'c'より右に2つの'w'を見つけた場合
if (wcnt == 2) {
min_chiwawa_str_length =
Math.max(min_chiwawa_str_length, wlocate - clocate + 1);
break;
}
}
}
return min_chiwawa_str_length;
}
}
spacia