結果

問題 No.910 素数部分列
ユーザー htensai
提出日時 2019-12-10 12:23:25
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,123 bytes
コンパイル時間 3,029 ms
コンパイル使用メモリ 78,300 KB
実行使用メモリ 59,448 KB
最終ジャッジ日時 2024-06-24 00:45:08
合計ジャッジ時間 16,829 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 WA * 39
権限があれば一括ダウンロードができます

ソースコード

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