結果
問題 | No.345 最小チワワ問題 |
ユーザー | spacia |
提出日時 | 2016-06-02 13:19:38 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 134 ms / 2,000 ms |
コード長 | 1,617 bytes |
コンパイル時間 | 3,071 ms |
コンパイル使用メモリ | 77,940 KB |
実行使用メモリ | 57,804 KB |
最終ジャッジ日時 | 2023-10-26 03:55:20 |
合計ジャッジ時間 | 7,692 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 128 ms
57,320 KB |
testcase_01 | AC | 134 ms
57,484 KB |
testcase_02 | AC | 130 ms
57,272 KB |
testcase_03 | AC | 129 ms
57,352 KB |
testcase_04 | AC | 130 ms
57,476 KB |
testcase_05 | AC | 130 ms
57,472 KB |
testcase_06 | AC | 129 ms
57,328 KB |
testcase_07 | AC | 128 ms
57,580 KB |
testcase_08 | AC | 126 ms
57,444 KB |
testcase_09 | AC | 128 ms
57,256 KB |
testcase_10 | AC | 128 ms
57,632 KB |
testcase_11 | AC | 128 ms
57,316 KB |
testcase_12 | AC | 129 ms
57,804 KB |
testcase_13 | AC | 129 ms
57,464 KB |
testcase_14 | AC | 132 ms
57,504 KB |
testcase_15 | AC | 132 ms
57,432 KB |
testcase_16 | AC | 131 ms
57,652 KB |
testcase_17 | AC | 129 ms
57,140 KB |
testcase_18 | AC | 131 ms
57,496 KB |
testcase_19 | AC | 129 ms
57,452 KB |
testcase_20 | AC | 127 ms
57,244 KB |
testcase_21 | AC | 125 ms
57,524 KB |
testcase_22 | AC | 127 ms
57,220 KB |
testcase_23 | AC | 125 ms
57,400 KB |
testcase_24 | AC | 129 ms
57,488 KB |
testcase_25 | AC | 126 ms
57,528 KB |
testcase_26 | AC | 128 ms
57,348 KB |
testcase_27 | AC | 127 ms
57,392 KB |
testcase_28 | AC | 129 ms
57,520 KB |
testcase_29 | AC | 129 ms
57,548 KB |
testcase_30 | AC | 131 ms
57,536 KB |
testcase_31 | AC | 130 ms
57,452 KB |
ソースコード
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) { if (min_chiwawa_str_length == -1) min_chiwawa_str_length = Integer.MAX_VALUE; min_chiwawa_str_length = Math.min(min_chiwawa_str_length, wlocate - clocate + 1); break; } } } return min_chiwawa_str_length; } }