結果

問題 No.910 素数部分列
ユーザー hrbt__
提出日時 2019-11-26 20:47:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 928 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 82,068 KB
実行使用メモリ 92,648 KB
最終ジャッジ日時 2024-11-07 00:55:42
合計ジャッジ時間 11,356 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 20 TLE * 4 -- * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
n = int(input())
s = input()
s = ''.join(s.split('3'))
s = ''.join(s.split('5'))
s = ''.join(s.split('7'))
ans = n - len(s)
n = len(s)
rl = []
p = 0
for i in range(n - 1):
    if s[i] != s[i + 1]:
        rl.append(s[p:i + 1])
        p = i + 1
rl.append(s[p:])
if rl[0][0] == '9':
    rl = [''] + rl 
if len(rl) % 2 != 0:
    rl = rl + ['']
m = len(rl)
cnt = [len(x) for x in rl]
# delete 19
for i in range(m - 2)[::2]:
    j = i + 1
    while j < m and cnt[i] > 0:
        c = min(cnt[i], cnt[j])
        ans += c
        cnt[i] -= c
        cnt[j] -= c
        j += 2
    cnt[i + 2] += cnt[i]
# delete 991
for i in range(m - 3)[1::2]:
    j = i + 1
    while j < m and cnt[i] > 1:
        c = min(cnt[i] // 2, cnt[j])
        ans += c
        cnt[i] -= 2 * c
        cnt[j] -= c
        j += 2
    cnt[i + 2] += cnt[i]
# delete 11
s = 0
for i in range(m)[::2]:
    s += cnt[i]
ans += s // 2
print(ans)
0