結果

問題 No.910 素数部分列
ユーザー htensai
提出日時 2020-01-07 11:20:51
言語 Java
(openjdk 23)
結果
AC  
実行時間 272 ms / 1,000 ms
コード長 1,000 bytes
コンパイル時間 5,323 ms
コンパイル使用メモリ 75,392 KB
実行使用メモリ 46,692 KB
最終ジャッジ日時 2024-11-23 00:41:51
合計ジャッジ時間 14,766 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

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();
        int count = 0;
        ArrayList<Integer> list = new ArrayList<>();
        for (char c : arr) {
            if (c == '3' || c == '5' || c == '7') {
                count++;
            } else {
                list.add(c - '0');
            }
        }
        int oneCount = 0;
        int nineCount = 0;
        for (int x : list) {
            if (x == 1) {
                oneCount++;
            } else {
                if (oneCount > 0) {
                    count++;
                    oneCount--;
                } else {
                    nineCount++;
                }
            }
        }
        int n991 = Math.min(nineCount / 2 , oneCount);
        count += n991;
        oneCount -= n991;
        count += oneCount / 2;
        System.out.println(count);
    }
}
0