結果

問題 No.910 素数部分列
ユーザー htensai
提出日時 2019-12-10 12:28:46
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,052 bytes
コンパイル時間 2,881 ms
コンパイル使用メモリ 76,856 KB
実行使用メモリ 58,796 KB
最終ジャッジ日時 2024-06-24 00:53:03
合計ジャッジ時間 14,836 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 28
権限があれば一括ダウンロードができます

ソースコード

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;
        int sum1 = 0;
        for (char c : arr) {
            if (c == '3' || c == '5' || c == '7') {
                count++;
            } else {
                if (c == '1') {
                    sum1++;
                }
                list.add(c - '0');
            }
        }
        int length = list.size();
        int sum9 = 0;
        int count9 = 0;
        for (int i = length - 1; i >= 0; i--) {
           if (list.get(i) == 9) {
                sum9++;
            } else {
                if (sum9 > 0) {
                    count9++;
                    sum9--;
                }
            }
        }
        count += count9;
        if (length > 0) {
            count += (sum1 - count9) / 2;
        }
        System.out.println(count);
  }
}
0