結果

問題 No.910 素数部分列
ユーザー tenten
提出日時 2020-08-26 20:50:41
言語 Java
(openjdk 23)
結果
AC  
実行時間 222 ms / 1,000 ms
コード長 770 bytes
コンパイル時間 2,205 ms
コンパイル使用メモリ 74,268 KB
実行使用メモリ 43,284 KB
最終ジャッジ日時 2024-11-07 13:38:02
合計ジャッジ時間 13,341 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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;
        int one = 0;
        int nine = 0;
        for (char c : arr) {
            if (c == '1') {
                one++;
            } else if (c == '9') {
                if (one > 0) {
                    count++;
                    one--;
                } else {
                    nine++;
                }
            } else {
                count++;
            }
        }
        int min = Math.min(nine / 2, one);
        count += min;
        one -= min;
         count += one / 2;
        System.out.println(count);
    }
}
0