結果

問題 No.910 素数部分列
ユーザー lam6er
提出日時 2025-03-31 17:43:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 657 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,532 KB
実行使用メモリ 96,120 KB
最終ジャッジ日時 2025-03-31 17:44:33
合計ジャッジ時間 4,871 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = input().strip()

count_357 = 0
s_prime = []
for c in s:
    if c in {'3', '5', '7'}:
        count_357 += 1
    else:
        s_prime.append(c)

cnt_19 = 0
cnt_9 = 0
c1_original = 0
c9_original = 0

# Calculate the number of 1's and 9's
for c in s_prime:
    if c == '1':
        c1_original += 1
    elif c == '9':
        c9_original += 1

# Reverse iterate to count 19s
for c in reversed(s_prime):
    if c == '9':
        cnt_9 += 1
    elif c == '1':
        if cnt_9 > 0:
            cnt_19 += 1
            cnt_9 -= 1

remaining_1 = c1_original - cnt_19
add_11 = remaining_1 // 2

total = count_357 + cnt_19 + add_11
print(total)
0