結果
問題 | No.345 最小チワワ問題 |
ユーザー | maruyuki95 |
提出日時 | 2018-01-08 01:40:02 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 144 ms / 2,000 ms |
コード長 | 1,274 bytes |
コンパイル時間 | 2,795 ms |
コンパイル使用メモリ | 90,536 KB |
実行使用メモリ | 57,812 KB |
最終ジャッジ日時 | 2023-10-26 04:21:28 |
合計ジャッジ時間 | 8,371 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 133 ms
57,376 KB |
testcase_01 | AC | 141 ms
57,352 KB |
testcase_02 | AC | 137 ms
57,192 KB |
testcase_03 | AC | 141 ms
57,584 KB |
testcase_04 | AC | 139 ms
57,356 KB |
testcase_05 | AC | 134 ms
57,368 KB |
testcase_06 | AC | 139 ms
57,348 KB |
testcase_07 | AC | 131 ms
57,812 KB |
testcase_08 | AC | 137 ms
57,488 KB |
testcase_09 | AC | 133 ms
57,336 KB |
testcase_10 | AC | 135 ms
57,320 KB |
testcase_11 | AC | 134 ms
57,332 KB |
testcase_12 | AC | 133 ms
57,276 KB |
testcase_13 | AC | 134 ms
57,580 KB |
testcase_14 | AC | 141 ms
57,612 KB |
testcase_15 | AC | 137 ms
57,296 KB |
testcase_16 | AC | 136 ms
57,656 KB |
testcase_17 | AC | 144 ms
57,312 KB |
testcase_18 | AC | 140 ms
57,300 KB |
testcase_19 | AC | 140 ms
57,460 KB |
testcase_20 | AC | 137 ms
57,356 KB |
testcase_21 | AC | 137 ms
57,548 KB |
testcase_22 | AC | 135 ms
57,332 KB |
testcase_23 | AC | 136 ms
57,348 KB |
testcase_24 | AC | 136 ms
57,280 KB |
testcase_25 | AC | 140 ms
57,280 KB |
testcase_26 | AC | 143 ms
57,592 KB |
testcase_27 | AC | 142 ms
57,156 KB |
testcase_28 | AC | 134 ms
57,520 KB |
testcase_29 | AC | 136 ms
57,624 KB |
testcase_30 | AC | 138 ms
57,344 KB |
testcase_31 | AC | 140 ms
57,348 KB |
ソースコード
import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); int ret = new Main().execute(s); System.out.println(ret); } private int execute(String arg) { List<Integer> cIndexs = findIndexs(arg, "c"); List<Integer> wIndexs = findIndexs(arg, "w"); List<Integer> chiwawaLengths = findChiwawaLengths(cIndexs, wIndexs); Optional<Integer> minLength = chiwawaLengths.stream().min((a, b) -> a.compareTo(b)); return minLength.orElse(-1); } private List<Integer> findIndexs(String origin, String target) { List<Integer> ret = new ArrayList<>(); int i = 0; while (origin.indexOf(target, i) > -1) { int index = origin.indexOf(target, i); ret.add(index); i = index + 1; } return ret; } private List<Integer> findChiwawaLengths(List<Integer> cIndexs, List<Integer> wIndexs) { List<Integer> ret = new ArrayList<>(); for (Integer cIndex : cIndexs) { int count = 0; for (Integer wIndex : wIndexs) { if(cIndex.compareTo(wIndex) > 0) { continue; } if(++count == 2) { ret.add(wIndex - cIndex + 1); break; } } } return ret; } }