結果

問題 No.1283 Extra Fee
ユーザー 👑 Nachia
提出日時 2020-11-06 21:41:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 911 bytes
コンパイル時間 1,405 ms
コンパイル使用メモリ 167,444 KB
実行使用メモリ 9,388 KB
最終ジャッジ日時 2024-07-22 12:31:13
合計ジャッジ時間 5,033 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 WA * 14
権限があれば一括ダウンロードができます

ソースコード

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