結果

問題 No.910 素数部分列
ユーザー koromo
提出日時 2019-12-05 03:19:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 93 ms / 1,000 ms
コード長 748 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 119,724 KB
最終ジャッジ日時 2024-12-15 07:24:58
合計ジャッジ時間 5,633 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

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