結果

問題 No.910 素数部分列
ユーザー mkawa2mkawa2
提出日時 2021-03-24 23:21:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 85 ms / 1,000 ms
コード長 1,333 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 11,012 KB
実行使用メモリ 10,188 KB
最終ジャッジ日時 2023-08-17 22:43:00
合計ジャッジ時間 5,034 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,192 KB
testcase_01 AC 17 ms
8,196 KB
testcase_02 AC 16 ms
8,200 KB
testcase_03 AC 16 ms
8,240 KB
testcase_04 AC 16 ms
8,200 KB
testcase_05 AC 17 ms
8,288 KB
testcase_06 AC 16 ms
8,296 KB
testcase_07 AC 16 ms
8,284 KB
testcase_08 AC 16 ms
7,952 KB
testcase_09 AC 16 ms
8,244 KB
testcase_10 AC 16 ms
8,284 KB
testcase_11 AC 16 ms
8,232 KB
testcase_12 AC 16 ms
8,244 KB
testcase_13 AC 16 ms
8,340 KB
testcase_14 AC 16 ms
8,196 KB
testcase_15 AC 16 ms
8,324 KB
testcase_16 AC 16 ms
8,252 KB
testcase_17 AC 16 ms
8,260 KB
testcase_18 AC 16 ms
8,192 KB
testcase_19 AC 16 ms
8,256 KB
testcase_20 AC 16 ms
8,264 KB
testcase_21 AC 16 ms
8,256 KB
testcase_22 AC 16 ms
8,296 KB
testcase_23 AC 78 ms
9,880 KB
testcase_24 AC 79 ms
10,148 KB
testcase_25 AC 77 ms
10,128 KB
testcase_26 AC 78 ms
10,180 KB
testcase_27 AC 78 ms
9,888 KB
testcase_28 AC 81 ms
10,040 KB
testcase_29 AC 80 ms
10,104 KB
testcase_30 AC 85 ms
10,136 KB
testcase_31 AC 78 ms
9,916 KB
testcase_32 AC 84 ms
10,140 KB
testcase_33 AC 84 ms
10,188 KB
testcase_34 AC 84 ms
10,080 KB
testcase_35 AC 82 ms
10,104 KB
testcase_36 AC 84 ms
10,036 KB
testcase_37 AC 82 ms
10,104 KB
testcase_38 AC 83 ms
10,036 KB
testcase_39 AC 82 ms
10,188 KB
testcase_40 AC 82 ms
10,104 KB
testcase_41 AC 82 ms
10,100 KB
testcase_42 AC 82 ms
10,088 KB
testcase_43 AC 83 ms
10,036 KB
testcase_44 AC 82 ms
10,104 KB
testcase_45 AC 82 ms
10,016 KB
testcase_46 AC 83 ms
10,064 KB
testcase_47 AC 83 ms
10,040 KB
testcase_48 AC 80 ms
10,104 KB
testcase_49 AC 69 ms
10,100 KB
testcase_50 AC 70 ms
10,100 KB
testcase_51 AC 75 ms
10,100 KB
testcase_52 AC 82 ms
10,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7

n=II()
aa=list(map(int,SI()))

# 3,5,7は1字で消せるのですぐ消す
# 残る1,9は11か19か991で消せる
# 11は一番最後に余った1で作る
# 19と991では19の方が消費字数が少ないので19優先で作る
# すると999...999111...111という形が残るはずなので、
# 991をできるだけ作って、残った1で11を作る
# かな?

ans=0
one=0
nine=0
for a in aa:
    if a==1:
        one+=1
    elif a==9:
        if one:
            ans+=1
            one-=1
        else:
            nine+=1
    else:
        ans+=1

c991=min(nine//2,one)
ans+=c991
ans+=(one-c991)//2

print(ans)
0