結果
問題 |
No.2924 <===Super Spaceship String===>
|
ユーザー |
|
提出日時 | 2024-10-12 16:57:36 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,513 bytes |
コンパイル時間 | 439 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 17,952 KB |
最終ジャッジ日時 | 2024-10-12 16:58:24 |
合計ジャッジ時間 | 3,868 ms |
ジャッジサーバーID (参考情報) |
judge / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 3 TLE * 1 -- * 7 |
ソースコード
S=list(input()) #ラングトン符号化→スタック s=[] N=len(S) for i in range(N): s.append([S[i],1]) ss=[s[0]] for i in range(1,N): if ss[-1][0]==s[i][0]: ss[-1][1]+=s[i][1] else: ss.append(s[i]) mai=0 stac=[] for i in range(len(ss)): f=True while f: f=False if len(stac)>=2: if stac[-1][0]==stac[-2][0]: f=True stac[-1][1]+=stac[-2][1] if len(stac)>=3: if stac[-3][0]=="<" and stac[-2][0]=="=" and stac[-1][0]==">": f=True mai+=stac[-2][1]+2 tmp=[stac[-3][1]-1,stac[-1][1]-1] for _ in range(3): stac.pop() if tmp[0]: stac.append(["<",tmp[0]]) if tmp[1]: stac.append([">",tmp[1]]) stac.append(ss[i]) f=True while f: f=False if len(stac)>=2: if stac[-1][0]==stac[-2][0]: f=True stac[-1][1]+=stac[-2][1] if len(stac)>=3: if stac[-3][0]=="<" and stac[-2][0]=="=" and stac[-1][0]==">": f=True mai+=stac[-2][1]+2 tmp=[stac[-3][1]-1,stac[-1][1]-1] for _ in range(3): stac.pop() if tmp[0]: stac.append(["<",tmp[0]]) if tmp[1]: stac.append([">",tmp[1]]) print(N-mai)