結果
問題 |
No.2064 Smallest Sequence on Grid
|
ユーザー |
![]() |
提出日時 | 2023-06-11 19:58:27 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,325 bytes |
コンパイル時間 | 355 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 293,888 KB |
最終ジャッジ日時 | 2025-01-03 04:09:23 |
合計ジャッジ時間 | 44,235 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 RE * 2 TLE * 9 |
ソースコード
# 辞書順最小だから前から決めていく # 斜め線上にあるアルファベットで最小のものを全部残しその次のものからも最小を選ぶ H, W = map(int, input().split()) S = [] for i in range(H): temp = input() S.append(temp) usable = [[0]*W for h in range(H)] usable[0][0] = 1 ans = S[0][0] for d in range(1, H+W-1): if d < W: start = (0, d) length = min(H, d+1) else: start = (d - (W-1), W-1) length = H - (d - (W-1)) #print('d', d, 'start', start, 'length', length) smallest = 'zz' #辞書順最悪ダミー smallest_index = [] for i in range(length): if (start[0]+i-1 >= 0 and usable[start[0]+i-1][start[1]-i] == 1) or (start[1]-i-1 >=0 and usable[start[0]+i][start[1]-i-1] == 1): letter = S[start[0]+i][start[1]-i] if letter == smallest: smallest_index.append(start[0]+i) elif letter < smallest: smallest = letter smallest_index = [] smallest_index.append(start[0]+i) #print(smallest, smallest_index) ans += smallest for i in range(length): if start[0]+i in smallest_index: usable[start[0]+i][start[1]-i] = 1 #print(usable) #print() print(ans)