結果
| 問題 | 
                            No.910 素数部分列
                             | 
                    
| コンテスト | |
| ユーザー | 
                             hrbt__
                         | 
                    
| 提出日時 | 2019-11-26 20:39:28 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 870 bytes | 
| コンパイル時間 | 185 ms | 
| コンパイル使用メモリ | 12,928 KB | 
| 実行使用メモリ | 16,256 KB | 
| 最終ジャッジ日時 | 2024-11-07 00:55:03 | 
| 合計ジャッジ時間 | 5,415 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 19 WA * 1 TLE * 2 -- * 28 | 
ソースコード
#!/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]:
    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
# delete 991
for i in range(m)[1::2]:
    j = i + 1
    while j < m and cnt[i] > 0:
        c = min(cnt[i] // 2, cnt[j])
        ans += c
        cnt[i] -= 2 * c
        cnt[j] -= c
        j += 2
# delete 11
s = 0
for i in range(m)[::2]:
    s += cnt[i]
ans += s // 2
print(ans)
            
            
            
        
            
hrbt__