結果
| 問題 | 
                            No.2064 Smallest Sequence on Grid
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kozy
                         | 
                    
| 提出日時 | 2022-09-02 21:52:48 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,502 bytes | 
| コンパイル時間 | 546 ms | 
| コンパイル使用メモリ | 82,340 KB | 
| 実行使用メモリ | 100,800 KB | 
| 最終ジャッジ日時 | 2024-11-16 03:14:29 | 
| 合計ジャッジ時間 | 9,853 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 11 WA * 18 | 
ソースコード
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
#roop=0
while True:
  #roop+=1
  #if roop==50:
  #  exit()
  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]
    K=T
    #print(A)
    if not flag:
      for _ in range(i-1):
        ans.append(c)
      ans.append(t)
      #print(A)
      A=P
      break
print("".join(ans))
            
            
            
        
            
kozy