結果

問題 No.1283 Extra Fee
ユーザー onsen_manjuuuonsen_manjuuu
提出日時 2020-11-06 22:09:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 451 ms / 2,000 ms
コード長 1,466 bytes
コンパイル時間 1,805 ms
コンパイル使用メモリ 182,612 KB
実行使用メモリ 76,364 KB
最終ジャッジ日時 2023-08-10 06:00:05
合計ジャッジ時間 8,910 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 17 ms
7,004 KB
testcase_12 AC 21 ms
7,748 KB
testcase_13 AC 15 ms
5,904 KB
testcase_14 AC 70 ms
15,720 KB
testcase_15 AC 115 ms
23,284 KB
testcase_16 AC 22 ms
7,248 KB
testcase_17 AC 309 ms
69,832 KB
testcase_18 AC 392 ms
69,252 KB
testcase_19 AC 429 ms
72,124 KB
testcase_20 AC 399 ms
67,828 KB
testcase_21 AC 405 ms
68,968 KB
testcase_22 AC 370 ms
61,860 KB
testcase_23 AC 355 ms
74,380 KB
testcase_24 AC 427 ms
74,272 KB
testcase_25 AC 451 ms
74,664 KB
testcase_26 AC 443 ms
74,636 KB
testcase_27 AC 446 ms
74,548 KB
testcase_28 AC 445 ms
74,380 KB
testcase_29 AC 329 ms
76,364 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:47:34: 警告: 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