結果

問題 No.2064 Smallest Sequence on Grid
ユーザー xZen1xZen1
提出日時 2022-09-02 23:27:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,037 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 82,056 KB
実行使用メモリ 444,380 KB
最終ジャッジ日時 2024-04-27 23:09:15
合計ジャッジ時間 8,634 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
69,176 KB
testcase_01 AC 53 ms
70,860 KB
testcase_02 AC 41 ms
61,644 KB
testcase_03 AC 48 ms
69,552 KB
testcase_04 AC 47 ms
69,252 KB
testcase_05 AC 48 ms
65,944 KB
testcase_06 AC 70 ms
77,024 KB
testcase_07 AC 61 ms
74,704 KB
testcase_08 AC 92 ms
76,964 KB
testcase_09 AC 92 ms
76,620 KB
testcase_10 AC 133 ms
77,084 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 212 ms
77,096 KB
testcase_16 WA -
testcase_17 TLE -
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 #

import random
h,w = map(int,input().split())
S = [list(input()) for _ in range(h)]

Ans = 'z'*10000
for _ in range(10**4):
    ans = S[0][0]
    a,b = 0,0
    for _ in range(h+w):
        if a == h-1 and b == w-1:
            if ans < Ans:
                Ans = ans
            else:
                break
        else:
            if a+1 == h:
                ans += S[a][b+1]
                b += 1
            elif b+1 == w:
                ans += S[a+1][b]
                a += 1
            else:
                if S[a+1][b] > S[a][b+1]:
                    ans += S[a][b+1]
                    b += 1
                elif S[a+1][b] < S[a][b+1]:
                    ans += S[a+1][b]
                    a += 1
                else:
                    R = random.randint(0,1)
                    if R == 1:
                        ans += S[a][b+1]
                        b += 1
                    else:
                        ans += S[a+1][b]
                        a += 1
print(Ans)                      
            
        
0