結果

問題 No.1283 Extra Fee
ユーザー tkmst201tkmst201
提出日時 2021-02-16 18:13:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,472 bytes
コンパイル時間 2,593 ms
コンパイル使用メモリ 217,852 KB
実行使用メモリ 20,012 KB
最終ジャッジ日時 2023-10-11 07:41:02
合計ジャッジ時間 9,144 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 12 ms
4,400 KB
testcase_17 AC 149 ms
18,808 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 162 ms
17,924 KB
testcase_24 AC 179 ms
17,936 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 166 ms
20,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N, M;
	cin >> N >> M;
	vector C(N, vector<int>(N));
	REP(i, M) {
		int h, w, c;
		scanf("%d %d %d", &h, &w, &c);
		C[h - 1][w - 1] = c;
	}
	vector dp(N, vector(N, vector(2, longINF)));
	using tup = tuple<ll, int, int>;
	priority_queue<tup, vector<tup>, greater<tup>> pq;
	dp[0][0][0] = 0;
	pq.emplace(0, 0, 0);
	while (!pq.empty()) {
		auto [c, p, f] = pq.top(); pq.pop();
		int y = p / N, x = p % N;
		if (c != dp[y][x][f]) continue;
		int dx[] {1,0,-1,0}, dy[] {0,1,0,-1};
		REP(dir, 4) {
			const int ny = y + dy[dir], nx = x + dx[dir];
			if (ny < 0 || ny >= N || nx < 0 || nx >= N) continue;
			if (chmin(dp[ny][nx][f], dp[y][x][f] + C[ny][nx])) pq.emplace(dp[ny][nx][f], ny * N + nx, f);
			if (!f && chmin(dp[ny][nx][1], dp[y][x][f])) pq.emplace(dp[ny][nx][1], ny * N + nx, 1);
		}
	}
	
	cout << dp[N - 1][N - 1][1] + 2 * (N - 1) << endl;
}
0