結果
問題 | No.1690 Power Grid |
ユーザー | miscalc |
提出日時 | 2021-09-24 22:35:28 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 961 ms / 3,000 ms |
コード長 | 2,415 bytes |
コンパイル時間 | 1,976 ms |
コンパイル使用メモリ | 210,556 KB |
実行使用メモリ | 81,172 KB |
最終ジャッジ日時 | 2024-07-05 11:00:17 |
合計ジャッジ時間 | 15,583 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 710 ms
62,736 KB |
testcase_07 | AC | 702 ms
62,740 KB |
testcase_08 | AC | 703 ms
62,744 KB |
testcase_09 | AC | 722 ms
62,868 KB |
testcase_10 | AC | 553 ms
48,532 KB |
testcase_11 | AC | 925 ms
79,124 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 3 ms
6,944 KB |
testcase_14 | AC | 73 ms
10,120 KB |
testcase_15 | AC | 961 ms
81,168 KB |
testcase_16 | AC | 717 ms
62,736 KB |
testcase_17 | AC | 334 ms
32,016 KB |
testcase_18 | AC | 157 ms
16,652 KB |
testcase_19 | AC | 739 ms
62,740 KB |
testcase_20 | AC | 730 ms
62,868 KB |
testcase_21 | AC | 504 ms
46,360 KB |
testcase_22 | AC | 821 ms
70,936 KB |
testcase_23 | AC | 925 ms
81,172 KB |
testcase_24 | AC | 845 ms
75,028 KB |
testcase_25 | AC | 848 ms
77,080 KB |
testcase_26 | AC | 872 ms
79,120 KB |
testcase_27 | AC | 2 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/modint> using namespace std; using namespace atcoder; using mint = modint998244353; //using mint = modint1000000007; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using tlll = tuple<ll, ll, ll>; constexpr ll INF = 1LL << 60; template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} ll safemod(ll A, ll M) {return (A % M + M) % M;} ll divfloor(ll A, ll B) {if (B < 0) {return divfloor(-A, -B);} return (A - safemod(A, B)) / B;} ll divceil(ll A, ll B) {if (B < 0) {return divceil(-A, -B);} return divfloor(A + B - 1, B);} #define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false) int main() { ll N, M, K; cin >> N >> M >> K; vector<ll> A(N); for (ll i = 0; i < N; i++) { cin >> A.at(i); } vector<vector<ll>> dist(N, vector<ll>(N, INF)); for (ll i = 0; i < M; i++) { ll x, y, z; cin >> x >> y >> z; x--, y--; dist.at(x).at(y) = z; dist.at(y).at(x) = z; } for (ll i = 0; i < N; i++) { dist.at(i).at(i) = 0; } for (ll k = 0; k < N; k++) { for (ll i = 0; i < N; i++) { for (ll j = 0; j < N; j++) { chmin(dist.at(i).at(j), dist.at(i).at(k) + dist.at(k).at(j)); } } } /* for (ll i = 0; i < N; i++) { for (ll j = 0; j < N; j++) { cerr << dist.at(i).at(j) << " "; } cerr << endl; } //*/ vector<vector<ll>> cost(N, vector<ll>((1LL << N), INF)); for (ll i = 0; i < N; i++) { for (ll b = 0; b < (1LL << N); b++) { for (ll j = 0; j < N; j++) { if (b & (1LL << j)) chmin(cost.at(i).at(b), dist.at(i).at(j)); if (b == 0) cost.at(i).at(b) = 0; } } } vector<vector<ll>> dp(K + 1, vector<ll>((1LL << N), INF)); dp.at(0).at(0) = 0; for (ll i = 0; i < K; i++) { for (ll b = 0; b < (1LL << N); b++) { for (ll j = 0; j < N; j++) { if (b & (1LL << j)) continue; ll nb = b | (1LL << j); if (chmin(dp.at(i + 1).at(nb), dp.at(i).at(b) + A.at(j) + cost.at(j).at(b))) { //cerr << i << " " << b << endl; } } } } ll ans = INF; for (ll b = 0; b < (1LL << N); b++) { chmin(ans, dp.at(K).at(b)); } cout << ans << endl; }