結果

問題 No.910 素数部分列
ユーザー L-aquaL-aqua
提出日時 2019-12-05 03:19:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 126 ms / 1,000 ms
コード長 748 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 123,868 KB
最終ジャッジ日時 2023-08-21 17:50:57
合計ジャッジ時間 9,131 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,104 KB
testcase_01 AC 74 ms
71,568 KB
testcase_02 AC 73 ms
71,612 KB
testcase_03 AC 73 ms
71,376 KB
testcase_04 AC 72 ms
71,364 KB
testcase_05 AC 72 ms
71,100 KB
testcase_06 AC 73 ms
71,368 KB
testcase_07 AC 72 ms
71,156 KB
testcase_08 AC 71 ms
71,628 KB
testcase_09 AC 73 ms
71,404 KB
testcase_10 AC 73 ms
71,620 KB
testcase_11 AC 73 ms
71,320 KB
testcase_12 AC 74 ms
71,476 KB
testcase_13 AC 71 ms
71,304 KB
testcase_14 AC 72 ms
71,320 KB
testcase_15 AC 73 ms
71,592 KB
testcase_16 AC 72 ms
71,152 KB
testcase_17 AC 74 ms
71,304 KB
testcase_18 AC 74 ms
71,396 KB
testcase_19 AC 74 ms
71,156 KB
testcase_20 AC 73 ms
71,328 KB
testcase_21 AC 74 ms
71,372 KB
testcase_22 AC 73 ms
71,152 KB
testcase_23 AC 113 ms
97,816 KB
testcase_24 AC 110 ms
98,252 KB
testcase_25 AC 113 ms
98,020 KB
testcase_26 AC 110 ms
97,932 KB
testcase_27 AC 112 ms
98,240 KB
testcase_28 AC 110 ms
98,312 KB
testcase_29 AC 118 ms
107,096 KB
testcase_30 AC 115 ms
107,264 KB
testcase_31 AC 115 ms
107,108 KB
testcase_32 AC 114 ms
107,168 KB
testcase_33 AC 114 ms
107,304 KB
testcase_34 AC 121 ms
107,660 KB
testcase_35 AC 118 ms
107,600 KB
testcase_36 AC 122 ms
107,504 KB
testcase_37 AC 121 ms
108,348 KB
testcase_38 AC 121 ms
108,044 KB
testcase_39 AC 122 ms
109,376 KB
testcase_40 AC 123 ms
110,148 KB
testcase_41 AC 123 ms
110,380 KB
testcase_42 AC 125 ms
111,244 KB
testcase_43 AC 123 ms
111,692 KB
testcase_44 AC 123 ms
110,976 KB
testcase_45 AC 123 ms
110,552 KB
testcase_46 AC 122 ms
109,076 KB
testcase_47 AC 121 ms
109,300 KB
testcase_48 AC 123 ms
122,256 KB
testcase_49 AC 125 ms
123,868 KB
testcase_50 AC 126 ms
123,732 KB
testcase_51 AC 96 ms
93,288 KB
testcase_52 AC 119 ms
113,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

prime = [3,5,7,11,19,991]
prime357 = [3,5,7]
import bisect
n = int(input())
s = list(map(int, list(input())))
count = 0
s_except357 = []
for i in s:
    if i in prime357:
        count += 1
    else:
        s_except357.append(i)
len19 = len(s_except357)
cnt1 = 0
list1 = []
next = []
for i in range(len19):
    if s_except357[i] == 1:
        cnt1 += 1
        list1.append(i)
    elif cnt1 > 0:
        list1.pop()
        count += 1
        cnt1 -= 1
    else:
        next.append(i)
next.extend(list1)
s_91 = [s_except357[i] for i in next]
s_91.sort()
center = bisect.bisect_left(s_91, 5)
one = center
nine = len(s_91) - center
if one >= nine//2:
    count += nine//2
    one -= nine//2
    count += one // 2
else:
    count += one
print(count)
0