結果

問題 No.910 素数部分列
ユーザー titiatitia
提出日時 2019-10-18 22:42:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 201 ms / 1,000 ms
コード長 1,223 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 13,292 KB
最終ジャッジ日時 2023-09-08 04:33:34
合計ジャッジ時間 7,710 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,108 KB
testcase_01 AC 16 ms
7,856 KB
testcase_02 AC 16 ms
8,268 KB
testcase_03 AC 16 ms
8,076 KB
testcase_04 AC 17 ms
8,088 KB
testcase_05 AC 16 ms
8,244 KB
testcase_06 AC 16 ms
8,240 KB
testcase_07 AC 17 ms
8,228 KB
testcase_08 AC 16 ms
8,180 KB
testcase_09 AC 16 ms
8,176 KB
testcase_10 AC 16 ms
8,100 KB
testcase_11 AC 16 ms
8,236 KB
testcase_12 AC 16 ms
8,224 KB
testcase_13 AC 16 ms
8,228 KB
testcase_14 AC 16 ms
8,180 KB
testcase_15 AC 17 ms
8,088 KB
testcase_16 AC 16 ms
8,252 KB
testcase_17 AC 16 ms
8,048 KB
testcase_18 AC 16 ms
8,184 KB
testcase_19 AC 16 ms
8,196 KB
testcase_20 AC 16 ms
8,084 KB
testcase_21 AC 16 ms
8,124 KB
testcase_22 AC 16 ms
8,180 KB
testcase_23 AC 99 ms
9,740 KB
testcase_24 AC 101 ms
9,888 KB
testcase_25 AC 101 ms
10,004 KB
testcase_26 AC 101 ms
10,028 KB
testcase_27 AC 102 ms
9,804 KB
testcase_28 AC 103 ms
10,008 KB
testcase_29 AC 190 ms
11,908 KB
testcase_30 AC 189 ms
11,592 KB
testcase_31 AC 184 ms
11,520 KB
testcase_32 AC 186 ms
11,592 KB
testcase_33 AC 191 ms
11,728 KB
testcase_34 AC 194 ms
11,688 KB
testcase_35 AC 193 ms
11,732 KB
testcase_36 AC 195 ms
11,604 KB
testcase_37 AC 195 ms
11,720 KB
testcase_38 AC 196 ms
11,780 KB
testcase_39 AC 199 ms
11,724 KB
testcase_40 AC 196 ms
12,344 KB
testcase_41 AC 198 ms
12,232 KB
testcase_42 AC 201 ms
12,228 KB
testcase_43 AC 195 ms
12,408 KB
testcase_44 AC 192 ms
12,308 KB
testcase_45 AC 192 ms
12,268 KB
testcase_46 AC 193 ms
12,300 KB
testcase_47 AC 197 ms
11,728 KB
testcase_48 AC 185 ms
13,292 KB
testcase_49 AC 177 ms
13,184 KB
testcase_50 AC 177 ms
13,280 KB
testcase_51 AC 43 ms
8,684 KB
testcase_52 AC 185 ms
11,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
S=input()

ANS=0

REST=[]

for x in S:
    if x in {"3","5","7"}:
        ANS+=1
    else:
        REST.append(x)

ONE=0
NINE=0
LEN=len(REST)
USE=[0]*len(REST)

while True:
    while ONE<LEN and REST[ONE]!="1":
        ONE+=1

    NINE=max(ONE,NINE)

    while NINE<LEN and REST[NINE]!="9":
        NINE+=1

    if ONE==LEN or NINE==LEN:
        break
    
    else:
        ANS+=1
        USE[ONE]=1
        USE[NINE]=1
        ONE+=1
        NINE+=1

REST2=[]
for i in range(len(REST)):
    if USE[i]==0:
        REST2.append(REST[i])

REST=REST2

ONE=0
NINE1=0
NINE2=0
LEN=len(REST)
USE=[0]*len(REST)

for i in range(len(REST)):
    while NINE1<LEN and REST[NINE1]!="9":
        NINE1+=1

    NINE2=NINE1+1

    while NINE2<LEN and REST[NINE2]!="9":
        NINE2+=1

    ONE=max(NINE2,ONE)

    while ONE<LEN and REST[ONE]!="1":
        ONE+=1

    if NINE1>=LEN or NINE2>=LEN or ONE>=LEN:
        break

    else:
        ANS+=1
        USE[ONE]=1
        USE[NINE1]=1
        USE[NINE2]=1
        ONE+=1
        NINE1=NINE2+1
        NINE2+=1
        
REST2=[]
for i in range(len(REST)):
    if USE[i]==0:
        REST2.append(REST[i])

REST=REST2

#print(ANS,REST)

ANS+=REST.count("1")//2
print(ANS)
0