結果
| 問題 | No.3626 Not a Prefix |
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2026-08-18 03:23:49 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,896 bytes |
| 記録 | |
| コンパイル時間 | 251 ms |
| コンパイル使用メモリ | 95,976 KB |
| 実行使用メモリ | 392,652 KB |
| 最終ジャッジ日時 | 2026-08-18 03:24:04 |
| 合計ジャッジ時間 | 9,190 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 37 WA * 8 |
ソースコード
import sys
input = sys.stdin.readline
N,M=list(map(int,input().split()))
# Trie木(Next_node_idを一次元化しておこう)
Charcaters=26 # 文字数
Next_node_id=[-1]*Charcaters # "A"~"Z"それぞれについて、対応する次のノードのid
Parent_id=[-1] # 親ノード
Depth=[0] # Trieのノードの深さ
Count=[0] # Trieのノードの重複度
Count2=[0]
Nodes_id=1 # 以下、標準入力で与えられたN個の文字列を追加する実装
for i in range(N):
S=input().strip()
L=len(S)
NOW=0
for s in S:
NEXT=ord(s)-97
if Next_node_id[NOW*Charcaters+NEXT]==-1: # Nodeを追加する場合
Next_node_id[NOW*Charcaters+NEXT]=Nodes_id
Next_node_id+=[-1]*Charcaters
Parent_id.append(NOW)
Depth.append(Depth[NOW]+1)
Count.append(0)
Count2.append(1)
NOW=Nodes_id
Nodes_id+=1
else: # 追加しない場合
NOW=Next_node_id[NOW*Charcaters+NEXT]
Count2[NOW]+=1
Count[NOW]+=1 # 終端に印を付ける
NOW=0
IND=[0]*(len(Count)+10)
ANS=[]
shuutan=0
while True:
#print(NOW,ANS)
if IND[NOW]==26:
NOW=Parent_id[NOW]
if NOW==-1:
break
ANS.pop()
continue
if Next_node_id[NOW*Charcaters+IND[NOW]]==-1:
ANS.append(IND[NOW])
break
else:
IND[NOW]+=1
ANS.append(IND[NOW]-1)
NOW=Next_node_id[NOW*Charcaters+IND[NOW]-1]
shuutan+=Count[NOW]
if shuutan>N-M:
NOW=Parent_id[NOW]
ANS.pop()
continue
if Count2[NOW]<=N-M:
break
else:
pass
if ANS==[]:
print("No")
else:
print("Yes")
ANS2=[]
for ans in ANS:
ANS2.append(chr(ans+97))
print("".join(ANS2))
titia