結果
問題 |
No.910 素数部分列
|
ユーザー |
![]() |
提出日時 | 2019-11-26 20:49:09 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 928 bytes |
コンパイル時間 | 320 ms |
コンパイル使用メモリ | 82,244 KB |
実行使用メモリ | 93,664 KB |
最終ジャッジ日時 | 2024-11-07 00:55:48 |
合計ジャッジ時間 | 6,322 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 TLE * 2 -- * 23 |
ソースコード
#!/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]: if i > 1 and cnt[i - 2]: cnt[i] += cnt[i - 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 # delete 11 s = 0 for i in range(m)[::2]: s += cnt[i] ans += s // 2 print(ans)