結果
| 問題 |
No.2000 Distanced Characters
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:37:44 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 191 ms / 2,000 ms |
| コード長 | 1,417 bytes |
| コンパイル時間 | 302 ms |
| コンパイル使用メモリ | 82,104 KB |
| 実行使用メモリ | 77,204 KB |
| 最終ジャッジ日時 | 2025-03-20 20:38:20 |
| 合計ジャッジ時間 | 2,060 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 13 |
ソースコード
def main():
import sys
input = sys.stdin.read().split('\n')
ptr = 0
S = input[ptr].strip()
ptr += 1
# Read D matrix
D = []
while ptr < 27:
line = input[ptr].strip()
if not line:
ptr += 1
continue
D.append(list(map(int, line.split())))
ptr += 1
# Initialize last positions to -infinity
INITIAL = -float('inf')
last_pos = [INITIAL] * 26
mindist = [[float('inf')] * 26 for _ in range(26)]
for j in range(len(S)):
beta_char = S[j]
beta = ord(beta_char) - ord('a')
current_position = j + 1 # 1-based position
# Check all alphas that have been seen before
for alpha in range(26):
if last_pos[alpha] != INITIAL:
distance = current_position - last_pos[alpha]
if distance < mindist[alpha][beta]:
mindist[alpha][beta] = distance
# Update last position of beta
last_pos[beta] = current_position
# Prepare the output
output = []
for alpha in range(26):
line = []
for beta in range(26):
if mindist[alpha][beta] < D[alpha][beta]:
line.append('N')
else:
line.append('Y')
output.append(' '.join(line))
print('\n'.join(output))
if __name__ == '__main__':
main()
lam6er