結果

問題 No.1283 Extra Fee
ユーザー Mr.SpockMr.Spock
提出日時 2021-01-01 15:05:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,658 bytes
コンパイル時間 2,213 ms
コンパイル使用メモリ 176,000 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-04-19 11:41:43
合計ジャッジ時間 5,194 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,376 KB
testcase_01 AC 2 ms
5,632 KB
testcase_02 AC 2 ms
5,632 KB
testcase_03 AC 2 ms
5,632 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,760 KB
testcase_07 AC 3 ms
5,632 KB
testcase_08 AC 2 ms
5,632 KB
testcase_09 AC 3 ms
5,504 KB
testcase_10 AC 3 ms
5,632 KB
testcase_11 AC 9 ms
5,708 KB
testcase_12 AC 10 ms
5,760 KB
testcase_13 AC 7 ms
5,760 KB
testcase_14 AC 25 ms
5,632 KB
testcase_15 AC 40 ms
5,760 KB
testcase_16 AC 10 ms
5,376 KB
testcase_17 AC 117 ms
8,232 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 109 ms
6,656 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 119 ms
8,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using T = tuple<int, int, int, int>;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
priority_queue<T, vector<T>, greater<T>>p;
int dp[505][505][2];
int n, t;
const int nax = 1e9;
bool islegal(int i, int j) {
	return (i >= 0 && i < n && j >= 0 && j < n);
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> t;
	vector<vector<int>>v(n, vector<int>(n, 0));
	for (int i = 0; i < t; i++) {
		int x, y, val;
		cin >> x >> y >> val;
		--x, --y;
		v[x][y] += val;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			v[i][j] += 1;
		}
	}
	for (int i = 0; i < 501; i++) {
		for (int k = 0; k < 501; k++) {
			for (int q = 0; q < 2; q++) {
				dp[i][k][q] = nax;
			}
		}
	}
	dp[0][0][0] = 0;
	p.push({0, 0, 0, 0});
	while (!p.empty()) {
		T r = p.top();
		p.pop();
		int cur = get<0>(r);
		int x = get<1>(r);
		int y = get<2>(r);
		int state = get<3>(r);
		if (dp[x][y][state] != cur)continue;
		for (int k = 0; k < 4; k++) {
			int nx = x + dx[k];
			int ny = y + dy[k];
			//cout << nx << " " << ny << endl;
			if (islegal(nx, ny)) {
				if (dp[nx][ny][state] > cur + v[nx][ny]) {
					dp[nx][ny][state] = cur + v[nx][ny];
					p.push({dp[nx][ny][state], nx, ny, state});
				}
				if (state == 0) {
					if (dp[nx][ny][1] > cur + 1) {
						dp[nx][ny][1] = cur + 1;
						p.push({dp[nx][ny][1], nx, ny, 1});
					}
				}
			}
		}
	}
	// for (int i = 0; i < n; i++) {
	// 	for (int j = 0; j < n; j++) {
	// 		cout << dp[i][j][0] << " " << dp[i][j][1] << endl;
	// 	}
	// }
	cout << min(dp[n - 1][n - 1][1], dp[n - 1][n - 1][0]) << endl;
}
0