結果

問題 No.1283 Extra Fee
ユーザー onsen_manjuuuonsen_manjuuu
提出日時 2020-11-06 22:09:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 409 ms / 2,000 ms
コード長 1,466 bytes
コンパイル時間 1,627 ms
コンパイル使用メモリ 186,060 KB
実行使用メモリ 76,704 KB
最終ジャッジ日時 2024-04-27 23:18:37
合計ジャッジ時間 8,385 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 15 ms
7,168 KB
testcase_12 AC 19 ms
7,808 KB
testcase_13 AC 14 ms
6,944 KB
testcase_14 AC 61 ms
15,872 KB
testcase_15 AC 103 ms
23,296 KB
testcase_16 AC 20 ms
7,552 KB
testcase_17 AC 259 ms
70,088 KB
testcase_18 AC 362 ms
69,356 KB
testcase_19 AC 389 ms
72,312 KB
testcase_20 AC 369 ms
67,892 KB
testcase_21 AC 367 ms
69,000 KB
testcase_22 AC 335 ms
62,004 KB
testcase_23 AC 327 ms
74,644 KB
testcase_24 AC 384 ms
74,592 KB
testcase_25 AC 408 ms
74,564 KB
testcase_26 AC 402 ms
74,636 KB
testcase_27 AC 409 ms
74,596 KB
testcase_28 AC 409 ms
74,564 KB
testcase_29 AC 297 ms
76,704 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:47:34: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   47 |                         for(auto [ny, nx] : dir4(i, j)) {
      |                                  ^

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = long long;


//経路復元なしDijkstra法
template<class T> 
vector<T> dijkstra( const vector<vector<pair<int,T>>>& Hen, int start = 0){
	T INF = numeric_limits<T>::max();
	int N = Hen.size();
	vector<T> dist(N, INF);
	dist[start] = 0;
	priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> que;
	que.push({0, start});
	while(que.size()) {
		int ver = que.top().second;
		T cost = que.top().first; que.pop();
		if(cost != dist[ver])continue;
		for(auto i : Hen[ver]) {
			if(dist[i.first] > cost + i.second) {
				dist[i.first] = cost + i.second;
				que.push({dist[i.first], i.first});
			}
		}
	}
	return dist;
}

vector<pair<int,int>> dir4(int x, int y) {return {{x - 1, y}, {x, y - 1}, {x + 1, y}, {x, y + 1}};};

int main()
{
	int N, M; cin >> N >> M;
	vector<vector<int>> grid(N, vector<int>(N, 1));
	for(int i = 0; i < M; i++) {
		int h, w, c; cin >> h >> w >> c; grid[h - 1][w - 1] += c;
	}
	int K = N * N;



	vector<vector<pair<int,ll>>> hen(2 * N * N);
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			int cur = i * N + j;
			for(auto [ny, nx] : dir4(i, j)) {
				if(ny < 0 || nx < 0 || ny >= N || nx >= N)continue;
				int nxt = ny * N + nx;
				hen[cur].push_back({nxt, grid[ny][nx]});
				hen[cur + K].push_back({nxt + K, grid[ny][nx]});
				hen[cur].push_back({nxt + K, 1});
			}
		}
	}


	vector<ll> dist = dijkstra(hen);
	cout << dist[2 * K - 1] << endl;

}
0