結果
問題 | No.2064 Smallest Sequence on Grid |
ユーザー |
![]() |
提出日時 | 2023-01-21 01:37:11 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,821 ms / 3,000 ms |
コード長 | 982 bytes |
コンパイル時間 | 398 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 182,060 KB |
最終ジャッジ日時 | 2024-06-23 13:13:08 |
合計ジャッジ時間 | 23,431 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 |
ソースコード
import sysreadline = sys.stdin.readlinedef alp_to_num(cha):num = ord(cha) - ord("a")return numH, W = map(int, readline().split())S = []for i in range(H):L = list(readline().rstrip())L = list(map(alp_to_num, L))S.append(L)x, y = 0, 0pre = [[] for i in range(26)]pre[S[0][0]].append(0)dx, dy = [1, 0], [0, 1]ans = []for i in range(H + W - 1):dp = [[] for i in range(26)]SS = set()for i, lst in enumerate(pre):if lst:ans.append(chr(i + ord("a")))for z in lst:nx, ny = divmod(z, W)for k in range(2):x = nx + dx[k]y = ny + dy[k]if x == H or y == W:continueif (x, y) in SS:continueSS.add((x, y))dp[S[x][y]].append(x * W + y)breakdp, pre = pre, dpprint(*ans, sep="")