結果

問題 No.2064 Smallest Sequence on Grid
ユーザー kozykozy
提出日時 2022-09-02 21:52:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,502 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 81,904 KB
実行使用メモリ 100,860 KB
最終ジャッジ日時 2024-04-27 21:24:09
合計ジャッジ時間 9,373 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
52,224 KB
testcase_01 AC 33 ms
52,224 KB
testcase_02 AC 35 ms
52,096 KB
testcase_03 AC 35 ms
51,840 KB
testcase_04 AC 34 ms
52,096 KB
testcase_05 AC 34 ms
52,736 KB
testcase_06 WA -
testcase_07 AC 37 ms
52,096 KB
testcase_08 AC 37 ms
52,608 KB
testcase_09 AC 39 ms
52,480 KB
testcase_10 AC 42 ms
52,992 KB
testcase_11 WA -
testcase_12 AC 38 ms
53,760 KB
testcase_13 WA -
testcase_14 AC 48 ms
63,104 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 1,354 ms
100,676 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

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
#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))
0