結果

問題 No.2064 Smallest Sequence on Grid
ユーザー kozykozy
提出日時 2022-09-02 21:49:50
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,417 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 82,520 KB
実行使用メモリ 83,364 KB
最終ジャッジ日時 2024-04-27 21:19:46
合計ジャッジ時間 5,955 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
60,800 KB
testcase_01 AC 39 ms
52,836 KB
testcase_02 AC 39 ms
53,072 KB
testcase_03 AC 38 ms
52,504 KB
testcase_04 AC 39 ms
53,404 KB
testcase_05 AC 38 ms
53,292 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

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
  K=set()
  K.add(tuple(A))
  flag=True
  c=1
  for i in range(1,H+W+1):
    #Aからiマスまで移動したやつたち
    T=set()
    for a,b in K:
      if (a,b)==(H-1,W-1):
        flag=False
        t=c
        P=[H-1,W-1]
        break
      if f(a,b+1):
        if c==1:
          c=L[a][b+1]
          P=[a,b+1]
          t=c
        elif c!=L[a][b+1]:
          flag=False
          if t>=L[a][b+1]:
            t=min(t,L[a][b+1])
            P=[a,b+1]
        T.add((a,b+1))
        if not flag:
          if t>=L[a][b+1]:
            P=[a,b+1]
            t=L[a][b+1]
      if f(a+1,b):
        T.add((a+1,b))
        if c==1:
          c=L[a+1][b]
          P=[a+1,b]
          t=c
        elif c!=L[a+1][b]:
          flag=False
          if t>=L[a+1][b]:
            t=min(t,L[a+1][b])
            P=[a+1,b]
        if not flag:
          if t>=L[a+1][b]:
            P=[a+1,b]
            t=L[a+1][b]
    if not flag:
      for _ in range(i-1):
        ans.append(c)
      ans.append(t)
      A=P
      break
print("".join(ans))
0