結果

問題 No.1283 Extra Fee
ユーザー 👑 NachiaNachia
提出日時 2020-11-06 21:53:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 455 ms / 2,000 ms
コード長 1,145 bytes
コンパイル時間 1,609 ms
コンパイル使用メモリ 172,476 KB
実行使用メモリ 22,524 KB
最終ジャッジ日時 2024-04-27 23:15:29
合計ジャッジ時間 8,257 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,948 KB
testcase_11 AC 21 ms
7,704 KB
testcase_12 AC 25 ms
6,944 KB
testcase_13 AC 17 ms
7,892 KB
testcase_14 AC 69 ms
8,512 KB
testcase_15 AC 112 ms
8,600 KB
testcase_16 AC 22 ms
6,944 KB
testcase_17 AC 388 ms
21,476 KB
testcase_18 AC 415 ms
9,628 KB
testcase_19 AC 435 ms
9,616 KB
testcase_20 AC 421 ms
9,556 KB
testcase_21 AC 406 ms
9,696 KB
testcase_22 AC 371 ms
9,596 KB
testcase_23 AC 323 ms
9,464 KB
testcase_24 AC 386 ms
9,768 KB
testcase_25 AC 444 ms
9,640 KB
testcase_26 AC 449 ms
9,648 KB
testcase_27 AC 455 ms
9,548 KB
testcase_28 AC 438 ms
9,776 KB
testcase_29 AC 410 ms
22,524 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];

struct QueueNode {
	int x, y, t;
	LL d;
};

bool operator<(QueueNode l, QueueNode r) { return l.d > r.d; }

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] = -1;

	priority_queue<QueueNode> G;
	G.push({ N - 1,N - 1,0,0 });
	G.push({ N - 1,N - 1,1,0 });

	const int dx[4][2] = { {1,0},{-1,0},{0,1},{0,-1} };

	while (G.size()) {
		int x = G.top().x;
		int y = G.top().y;
		int t = G.top().t;
		LL d = G.top().d;
		G.pop();

		if (x < 0 || x >= N) continue;
		if (y < 0 || y >= N) continue;
		if (dp[x][y][t] != -1) continue;

		dp[x][y][t] = d;

		rep(di, 4) {
			G.push({ x + dx[di][0], y + dx[di][1], t, d + D[x][y] });
		}

		if (t < 1) {
			rep(di, 4) {
				G.push({ x + dx[di][0], y + dx[di][1], t + 1, d + 1 });
			}
		}
	}

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

	return 0;
}
0