結果
問題 | No.910 素数部分列 |
ユーザー |
![]() |
提出日時 | 2019-10-18 22:42:02 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 246 ms / 1,000 ms |
コード長 | 1,223 bytes |
コンパイル時間 | 171 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 16,108 KB |
最終ジャッジ日時 | 2024-06-25 21:48:54 |
合計ジャッジ時間 | 8,390 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
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)