結果

問題 No.910 素数部分列
ユーザー htensaihtensai
提出日時 2019-12-10 12:23:25
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,123 bytes
コンパイル時間 2,174 ms
コンパイル使用メモリ 74,672 KB
実行使用メモリ 61,048 KB
最終ジャッジ日時 2023-09-06 06:05:09
合計ジャッジ時間 14,287 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
55,792 KB
testcase_01 AC 112 ms
53,836 KB
testcase_02 AC 113 ms
55,620 KB
testcase_03 WA -
testcase_04 AC 109 ms
55,752 KB
testcase_05 WA -
testcase_06 AC 113 ms
56,480 KB
testcase_07 WA -
testcase_08 AC 116 ms
55,392 KB
testcase_09 AC 108 ms
56,008 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 106 ms
55,764 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 111 ms
55,972 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 202 ms
59,140 KB
testcase_49 AC 208 ms
58,936 KB
testcase_50 AC 211 ms
58,968 KB
testcase_51 AC 190 ms
58,572 KB
testcase_52 AC 215 ms
57,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] arr = sc.next().toCharArray();
        ArrayList<Integer> list = new ArrayList<>();
        int count = 0;
        for (char c : arr) {
            if (c == '3' || c == '5' || c == '7') {
                count++;
            } else {
                list.add(c - '0');
            }
        }
        int length = list.size();
        int[] sums1 = new int[length];
        for (int i = 0; i < length; i++) {
            if (i != 0) {
                sums1[i] = sums1[i - 1];
            }
            if (list.get(i) == 1) {
                sums1[i]++;
            }
        }
        int max = 0;
        int sum9 = 0;
        for (int i = length - 1; i >= 0 && sum9 <= sums1[i]; i--) {
            max = sum9;
            if (list.get(i) == 9) {
                sum9++;
            }
        }
        count += max;
        if (length > 0) {
            count += (sums1[length - 1] - max) / 2;
        }
        System.out.println(count);
  }
}
0