結果
| 問題 | No.3626 Not a Prefix |
| コンテスト | |
| ユーザー |
kidodesu
|
| 提出日時 | 2026-08-14 22:41:40 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,240 bytes |
| 記録 | |
| コンパイル時間 | 222 ms |
| コンパイル使用メモリ | 96,116 KB |
| 実行使用メモリ | 126,292 KB |
| 最終ジャッジ日時 | 2026-08-14 22:41:48 |
| 合計ジャッジ時間 | 7,889 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 42 WA * 3 |
ソースコード
def main():
n, m = list(map(int, input().split()))
S = [input() for _ in range(n)]
i = 0
j = 0
Ans = []
while m and i < 26:
#print(Ans, m, S)
c = chr(97+i)
cnt = 0
cnt0 = 0
for s in S:
if s[j] == c and len(s)-1 == j:
cnt += 1
if s[j] != c:
cnt0 += 1
if m <= cnt0:
return "".join(Ans) + c
if len(S)-cnt < m:
T = []
for s in S:
if s[j] != c:
T.append(s)
else:
m -= 1
i += 1
if m <= 0 and i < 26:
return "".join(Ans) + chr(97+i)
S = T
else:
Ans.append(c)
T = []
for s in S:
if s[j] == c and len(s)-1 == j:
pass
elif s[j] != c:
m -= 1
else:
T.append(s)
if m <= 0:
return "".join(Ans) + c
else:
S = T
i = 0
j += 1
return ""
ans = main()
if ans == "":
print("No")
else:
print("Yes")
print(ans)
kidodesu