結果

問題 No.2095 High Rise
ユーザー laneguelanegue
提出日時 2022-10-07 23:45:36
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 586 bytes
コンパイル時間 2,695 ms
コンパイル使用メモリ 160,980 KB
実行使用メモリ 25,908 KB
最終ジャッジ日時 2023-09-04 18:32:37
合計ジャッジ時間 5,423 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 24 ms
8,432 KB
testcase_18 AC 16 ms
6,460 KB
testcase_19 AC 6 ms
4,548 KB
testcase_20 AC 25 ms
7,984 KB
testcase_21 AC 44 ms
9,936 KB
testcase_22 AC 179 ms
25,908 KB
testcase_23 AC 179 ms
25,796 KB
testcase_24 AC 180 ms
25,732 KB
testcase_25 AC 180 ms
25,780 KB
testcase_26 AC 180 ms
25,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;
void main(){
	auto a = readln.split.to!(long[]);
	auto N = a[0];
	auto M = a[1];
	long[][] A;
	for(auto n = 0; n < N; n++){
		A ~= readln.split.to!(long[]);
	}
	if(N == 1){
		writeln(0);
		return;
	}
	auto cost = new long[][](N + 1, M);
	for(auto n = 0; n < N; n++){
		long min_cost = cost[n].minElement;
		for(auto m = 0; m < M; m++){
			if(cost[n][m] == min_cost){
				cost[n + 1][m] = min_cost + A[n][m];
			}else{
				cost[n + 1][m] = min(min_cost + A[n][m] + A[n - 1][m], cost[n][m] + A[n][m]);
			}
		}
	}
	//stderr.writeln(cost);
	writeln(cost[$ - 1].minElement);
}

0