結果

問題 No.2064 Smallest Sequence on Grid
ユーザー kozy
提出日時 2022-09-02 22:08:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 845 bytes
コンパイル時間 355 ms
コンパイル使用メモリ 81,976 KB
実行使用メモリ 170,148 KB
最終ジャッジ日時 2024-11-16 03:44:56
合計ジャッジ時間 9,105 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13 WA * 15 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W=map(int,input().split())
L=list()
for i in range(H):
  s=input()
  L.append(s)
ans=list()
ans.append(L[0][0])
A=[0,0]
def f(x,y):
  if 0<=x<H and 0<=y<W:
    return True
  return False

while True:
  if A[0]==H-1:
    for i in range(A[1]+1,W):
      ans.append(L[A[0]][i])
    break
  if A[1]==W-1:
    for i in range(A[0]+1,H):
      ans.append(L[i][A[1]])
    break
  c=L[A[0]][A[1]+1]
  flag=True
  for i in range(1,H+W+1):
    for s in range(0,i+1):
      if f(A[0]+s,A[1]+i-s):
        if L[A[0]+s][A[1]+i-s]!=c:
          flag=False
    if not flag:
      t="z"
      for s in range(0,i+1):
        if f(A[0]+s,A[1]+i-s):
          if t>=L[A[0]+s][A[1]+i-s]:
            P=[A[0]+s,A[1]+i-s]
            t=L[A[0]+s][A[1]+i-s]
      for j in range(i-1):
        ans.append(c)
      ans.append(t)
      A=P
      break
print("".join(ans))
0