結果

問題 No.791 うし数列
ユーザー Yosuke YamaguchiYosuke Yamaguchi
提出日時 2021-01-18 23:57:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 921 bytes
コンパイル時間 3,805 ms
コンパイル使用メモリ 86,332 KB
実行使用メモリ 56,388 KB
最終ジャッジ日時 2023-08-21 07:22:36
合計ジャッジ時間 6,934 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,896 KB
testcase_01 AC 121 ms
56,244 KB
testcase_02 AC 120 ms
55,944 KB
testcase_03 AC 115 ms
55,620 KB
testcase_04 AC 122 ms
55,668 KB
testcase_05 AC 114 ms
55,972 KB
testcase_06 AC 114 ms
55,820 KB
testcase_07 AC 119 ms
55,684 KB
testcase_08 AC 126 ms
56,056 KB
testcase_09 AC 125 ms
56,384 KB
testcase_10 AC 122 ms
53,732 KB
testcase_11 AC 124 ms
56,036 KB
testcase_12 AC 123 ms
55,772 KB
testcase_13 AC 122 ms
55,648 KB
testcase_14 AC 121 ms
56,388 KB
testcase_15 AC 120 ms
55,640 KB
testcase_16 AC 122 ms
56,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

// https://yukicoder.me/problems/no/791
// エラーの解決の参考:https://zero-config.com/java/list0001.html
public class Ushi791 {
  public static void main(String[] args) {
    // 標準入力から読み込む際に、Scan
    Scanner sc = new Scanner(System.in);

    // String 1つ分を読み込む
    String s = sc.next();

    List<String> list = new LinkedList(Arrays.asList(s.split("")));
    if (!list.get(0).equals("1")) {
      System.out.println(-1);
      return;
    }
    list.remove(0);
    List<String> threeList = list.stream().filter(a -> a.equals("3")).collect(Collectors.toList());
    if (list.size() == threeList.size() && threeList.size() != 0) {
      System.out.println(threeList.size());
    } else {
      System.out.println(-1);
    }
  }
}
0