結果

問題 No.2064 Smallest Sequence on Grid
ユーザー ytftytft
提出日時 2022-09-03 19:40:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,315 ms / 3,000 ms
コード長 567 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 82,288 KB
実行使用メモリ 102,756 KB
最終ジャッジ日時 2024-04-28 16:53:51
合計ジャッジ時間 12,343 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,348 KB
testcase_01 AC 33 ms
52,940 KB
testcase_02 AC 33 ms
53,152 KB
testcase_03 AC 33 ms
53,108 KB
testcase_04 AC 34 ms
52,140 KB
testcase_05 AC 33 ms
53,188 KB
testcase_06 AC 34 ms
53,488 KB
testcase_07 AC 34 ms
53,496 KB
testcase_08 AC 35 ms
53,804 KB
testcase_09 AC 35 ms
53,592 KB
testcase_10 AC 36 ms
54,148 KB
testcase_11 AC 36 ms
54,088 KB
testcase_12 AC 42 ms
54,460 KB
testcase_13 AC 45 ms
63,576 KB
testcase_14 AC 48 ms
64,832 KB
testcase_15 AC 47 ms
63,840 KB
testcase_16 AC 49 ms
64,736 KB
testcase_17 AC 110 ms
84,932 KB
testcase_18 AC 107 ms
85,416 KB
testcase_19 AC 107 ms
85,396 KB
testcase_20 AC 952 ms
95,564 KB
testcase_21 AC 1,011 ms
96,668 KB
testcase_22 AC 697 ms
91,992 KB
testcase_23 AC 734 ms
93,948 KB
testcase_24 AC 738 ms
93,976 KB
testcase_25 AC 730 ms
94,088 KB
testcase_26 AC 1,315 ms
102,756 KB
testcase_27 AC 1,292 ms
102,452 KB
testcase_28 AC 108 ms
85,724 KB
testcase_29 AC 1,215 ms
95,916 KB
testcase_30 AC 118 ms
84,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda:sys.stdin.readline().rstrip()
def compare(a,b):
	return a if a<b else b
H,W=map(int,input().split())
S=[input() for i in range(H)]
ans=S[0][0]
pointer=[0]
for j in range(H+W-2):
	cand='{'
	new=set()
	for k in pointer:
		i=[k//W,k%W]
		if i[0]<H-1:
			cand=compare(cand,S[i[0]+1][i[1]])
		if i[1]<W-1:
			cand=compare(cand,S[i[0]][i[1]+1])
	for k in pointer:
		i=[k//W,k%W]
		if i[0]<H-1 and S[i[0]+1][i[1]]==cand:
			new.add((i[0]+1)*W+i[1])
		if i[1]<W-1 and S[i[0]][i[1]+1]==cand:
			new.add(i[0]*W+i[1]+1)
	pointer=new
	ans+=cand
print(ans)
0