結果

問題 No.910 素数部分列
ユーザー Chihaya_chan
提出日時 2020-06-14 00:44:51
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 220 ms / 1,000 ms
コード長 694 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-06-26 03:33:30
合計ジャッジ時間 8,000 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

# problem 1
N = int(input())
S = list(input())
ans = 0
dic = {"1": 0, "3": 0, "5": 0, "7": 0, "9": 0}
for some in S:
    dic[some] += 1

ans = dic["3"]+dic["5"]+dic["7"]
new = {1: 0, 9: 0}
for x in S:
    n = int(x)
    if n == 1: new[1] += 1
    if n == 9:
        new[9] += 1
        
        if new[9]>0 and new[1] > 0:
            new[1] -= 1
            new[9] -= 1
            ans += 1


if new[9] >= new[1]*2:
    ans += new[1]
    print(ans)
    exit()
    
elif new[9] < new[1]*2:

    if new[9]>1:
        p = new[9]//2
        ans += p
        new[1] -= p
        ans += new[1]//2
        print(ans)
        exit()
    else:
        ans += new[1]//2
        print(ans)
        exit()
0