結果

問題 No.910 素数部分列
ユーザー htensaihtensai
提出日時 2020-01-07 11:20:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 252 ms / 1,000 ms
コード長 1,000 bytes
コンパイル時間 2,414 ms
コンパイル使用メモリ 75,136 KB
実行使用メモリ 46,248 KB
最終ジャッジ日時 2024-05-02 11:18:55
合計ジャッジ時間 14,308 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
41,184 KB
testcase_01 AC 127 ms
40,664 KB
testcase_02 AC 118 ms
39,872 KB
testcase_03 AC 130 ms
41,364 KB
testcase_04 AC 130 ms
41,100 KB
testcase_05 AC 117 ms
39,808 KB
testcase_06 AC 129 ms
41,088 KB
testcase_07 AC 118 ms
40,128 KB
testcase_08 AC 117 ms
39,984 KB
testcase_09 AC 131 ms
41,052 KB
testcase_10 AC 130 ms
41,064 KB
testcase_11 AC 129 ms
41,168 KB
testcase_12 AC 131 ms
41,320 KB
testcase_13 AC 120 ms
39,952 KB
testcase_14 AC 131 ms
41,140 KB
testcase_15 AC 132 ms
41,232 KB
testcase_16 AC 130 ms
40,992 KB
testcase_17 AC 127 ms
41,292 KB
testcase_18 AC 129 ms
41,040 KB
testcase_19 AC 133 ms
41,228 KB
testcase_20 AC 130 ms
41,060 KB
testcase_21 AC 133 ms
41,548 KB
testcase_22 AC 119 ms
39,824 KB
testcase_23 AC 224 ms
44,552 KB
testcase_24 AC 229 ms
44,036 KB
testcase_25 AC 233 ms
43,912 KB
testcase_26 AC 222 ms
44,252 KB
testcase_27 AC 230 ms
44,320 KB
testcase_28 AC 236 ms
44,340 KB
testcase_29 AC 240 ms
45,964 KB
testcase_30 AC 245 ms
45,792 KB
testcase_31 AC 248 ms
46,044 KB
testcase_32 AC 249 ms
45,832 KB
testcase_33 AC 247 ms
46,104 KB
testcase_34 AC 244 ms
45,924 KB
testcase_35 AC 252 ms
45,764 KB
testcase_36 AC 245 ms
45,900 KB
testcase_37 AC 248 ms
45,712 KB
testcase_38 AC 246 ms
45,928 KB
testcase_39 AC 248 ms
45,836 KB
testcase_40 AC 249 ms
45,732 KB
testcase_41 AC 252 ms
45,780 KB
testcase_42 AC 247 ms
46,248 KB
testcase_43 AC 251 ms
45,760 KB
testcase_44 AC 241 ms
45,892 KB
testcase_45 AC 244 ms
45,872 KB
testcase_46 AC 242 ms
45,920 KB
testcase_47 AC 249 ms
46,092 KB
testcase_48 AC 242 ms
46,088 KB
testcase_49 AC 244 ms
46,104 KB
testcase_50 AC 246 ms
45,560 KB
testcase_51 AC 218 ms
43,132 KB
testcase_52 AC 247 ms
45,676 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();
        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