結果

問題 No.1283 Extra Fee
ユーザー 👑 NachiaNachia
提出日時 2020-11-06 21:41:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 911 bytes
コンパイル時間 1,532 ms
コンパイル使用メモリ 166,472 KB
実行使用メモリ 9,496 KB
最終ジャッジ日時 2023-09-29 18:29:04
合計ジャッジ時間 5,390 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,432 KB
testcase_01 AC 1 ms
5,364 KB
testcase_02 AC 2 ms
5,384 KB
testcase_03 AC 1 ms
5,396 KB
testcase_04 AC 2 ms
5,388 KB
testcase_05 AC 2 ms
5,384 KB
testcase_06 AC 1 ms
5,456 KB
testcase_07 AC 2 ms
5,404 KB
testcase_08 AC 2 ms
5,416 KB
testcase_09 AC 2 ms
5,440 KB
testcase_10 AC 2 ms
5,416 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 11 ms
6,368 KB
testcase_17 AC 41 ms
9,068 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 128 ms
9,352 KB
testcase_24 AC 181 ms
9,184 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 41 ms
9,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int N, M;
LL D[500][500];
LL dp[500][500][2];

int main() {
	cin >> N >> M;
	rep(i, N) rep(j, N) D[i][j] = 1; D[0][0] = 0;
	rep(i, M) {
		int y, x, c; cin >> y >> x >> c; y--; x--;
		D[x][y] += c;
	}

	rep(i, N) rep(j, N) rep(t, 2) dp[i][j][t] = 10000000000000;
	dp[0][0][0] = dp[0][0][1] = 0;

	rep(i, N) rep(j, N) {
		LL& tg0 = dp[i][j][0];
		LL& tg1 = dp[i][j][1];
		if (i != 0) {
			tg0 = min(tg0, dp[i - 1][j][0] + D[i][j]);
			tg1 = min(tg1, dp[i - 1][j][0] + 1);
			tg1 = min(tg1, dp[i - 1][j][1] + D[i][j]);
		}
		if (j != 0) {
			tg0 = min(tg0, dp[i][j - 1][0] + D[i][j]);
			tg1 = min(tg1, dp[i][j - 1][0] + 1);
			tg1 = min(tg1, dp[i][j - 1][1] + D[i][j]);
		}
	}

	LL ans = min(dp[N - 1][N - 1][0], dp[N - 1][N - 1][1]);
	cout << ans << endl;

	return 0;
}
0