結果

問題 No.1690 Power Grid
ユーザー kabipoyokabipoyo
提出日時 2022-01-13 17:33:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,140 bytes
コンパイル時間 3,909 ms
コンパイル使用メモリ 265,416 KB
実行使用メモリ 50,560 KB
最終ジャッジ日時 2024-04-28 14:26:19
合計ジャッジ時間 12,799 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
50,348 KB
testcase_01 AC 51 ms
50,304 KB
testcase_02 AC 48 ms
50,304 KB
testcase_03 AC 50 ms
50,432 KB
testcase_04 AC 48 ms
50,340 KB
testcase_05 AC 48 ms
50,432 KB
testcase_06 AC 424 ms
50,308 KB
testcase_07 AC 432 ms
50,336 KB
testcase_08 AC 431 ms
50,304 KB
testcase_09 AC 431 ms
50,352 KB
testcase_10 AC 448 ms
50,304 KB
testcase_11 WA -
testcase_12 AC 52 ms
50,416 KB
testcase_13 AC 51 ms
50,304 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 432 ms
50,316 KB
testcase_21 AC 523 ms
50,340 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 52 ms
50,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << "  ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;
lint node, start;
vvi dist(18, vi(18));  // 事前に準備しておく
vector<vector<lint>> dp((1<<18), vector<lint>(18, -1));
vi A(18);

lint rec(lint bit, lint v) {
	if (dp[bit][v] != -1) return dp[bit][v];
	if (bit == (1<<v)) return dp[bit][v] = start+A[v];
	lint res = LINF,  prev_bit = bit & ~(1<<v);
	for (lint u = 0; u < node; ++u) {
		if (!(prev_bit & (1<<u))) continue;
		chmin(res, rec(prev_bit, u) + dist[u][v] + A[v]);
	}
	return dp[bit][v] = res;
}

lint bitDP(lint N, lint s) {
	node = N, start = s;  // 初期コスト
	lint res = LINF;
	rep(i, node) chmin(res, rec((1<<node)-1, i));
	return res;
}

void Floyd_Warshall(lint N, lint M) {
	lint x, y, z;
	rep(i, N) {
		rep(j, N) {
			if (i == j) dist[i][j] = 0;
			else dist[i][j] = LINF;
		}
	}
	rep(i, M) {
		cin >> x >> y >> z;
		x--, y--;
		dist[x][y] = z;
		dist[y][x] = z;
	}
	rep(k, N) {
		rep(i, N) {
			rep(j, N) {
				chmin(dist[i][j], dist[i][k]+dist[k][j]);
			}
		}
	}
}

int main() {
	lint N, M, K;
	cin >> N >> M >> K;
	rep(i, N) cin >> A[i];
	Floyd_Warshall(N, M);

	lint a=LINF, b=0, c=0, x, y, z;
	bitDP(N, 0);
	rep(i, 1<<N) {
		if (__builtin_popcount(i) == K) {
			rep(j, N) {
				if (dp[i][j] != -1) chmin(a, dp[i][j]);
			}
		}
	}
	std::cout << a << '\n';
}
0