結果

問題 No.910 素数部分列
ユーザー stngstng
提出日時 2022-08-13 12:21:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 129 ms / 1,000 ms
コード長 734 bytes
コンパイル時間 1,247 ms
コンパイル使用メモリ 81,648 KB
実行使用メモリ 117,600 KB
最終ジャッジ日時 2023-10-24 21:12:50
合計ジャッジ時間 6,383 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
55,396 KB
testcase_01 AC 38 ms
55,396 KB
testcase_02 AC 36 ms
55,396 KB
testcase_03 AC 37 ms
55,396 KB
testcase_04 AC 37 ms
55,396 KB
testcase_05 AC 38 ms
55,396 KB
testcase_06 AC 37 ms
55,396 KB
testcase_07 AC 37 ms
55,396 KB
testcase_08 AC 36 ms
55,396 KB
testcase_09 AC 40 ms
55,396 KB
testcase_10 AC 37 ms
55,396 KB
testcase_11 AC 37 ms
55,396 KB
testcase_12 AC 37 ms
55,396 KB
testcase_13 AC 37 ms
55,396 KB
testcase_14 AC 37 ms
55,396 KB
testcase_15 AC 37 ms
55,396 KB
testcase_16 AC 37 ms
55,396 KB
testcase_17 AC 37 ms
55,396 KB
testcase_18 AC 37 ms
55,396 KB
testcase_19 AC 36 ms
55,396 KB
testcase_20 AC 37 ms
55,396 KB
testcase_21 AC 36 ms
55,396 KB
testcase_22 AC 37 ms
55,396 KB
testcase_23 AC 73 ms
88,504 KB
testcase_24 AC 74 ms
88,544 KB
testcase_25 AC 76 ms
88,660 KB
testcase_26 AC 74 ms
88,528 KB
testcase_27 AC 129 ms
87,304 KB
testcase_28 AC 75 ms
88,584 KB
testcase_29 AC 111 ms
107,492 KB
testcase_30 AC 109 ms
107,732 KB
testcase_31 AC 112 ms
109,500 KB
testcase_32 AC 111 ms
109,776 KB
testcase_33 AC 108 ms
107,820 KB
testcase_34 AC 113 ms
113,496 KB
testcase_35 AC 114 ms
112,532 KB
testcase_36 AC 116 ms
108,044 KB
testcase_37 AC 111 ms
107,752 KB
testcase_38 AC 114 ms
105,708 KB
testcase_39 AC 111 ms
105,800 KB
testcase_40 AC 110 ms
102,652 KB
testcase_41 AC 115 ms
106,464 KB
testcase_42 AC 110 ms
103,444 KB
testcase_43 AC 112 ms
105,260 KB
testcase_44 AC 111 ms
103,176 KB
testcase_45 AC 110 ms
106,792 KB
testcase_46 AC 110 ms
105,456 KB
testcase_47 AC 111 ms
105,844 KB
testcase_48 AC 77 ms
99,772 KB
testcase_49 AC 91 ms
102,324 KB
testcase_50 AC 91 ms
102,320 KB
testcase_51 AC 44 ms
61,880 KB
testcase_52 AC 107 ms
117,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n = int(input())
s = input()
li = []
ans = 0
for i in range(n):
    if s[i] != "1" and s[i] != "9":
        ans += 1
    else:
        li.append(s[i])

idx = set()
d1 = deque()
#d9 = deque()

for i in range(len(li)):
    if li[i] == "1":
        d1.append(i)
    if li[i] == "9":
        if len(d1) > 0:
            tmp = d1.popleft()
            idx.add(tmp)
            idx.add(i)
            ans += 1
        
li2 = []
for i in range(len(li)):
    if i not in idx:
        li2.append(li[i])
#print(li2,ans,len(li2))
#exit()

n9 = 0
n1 = 0
for i in range(len(li2)):
    if li2[i] == "1":
        n9 = i
        n1 = len(li2)-i
        break

tmp = min(n9//2,n1)
ans += tmp
ans += (n1-tmp)//2
print(ans)
0