QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#308216 | #6645. 百合 | ckiseki# | TL | 0ms | 0kb | C++20 | 1.6kb | 2024-01-19 18:59:08 | 2024-01-19 18:59:09 |
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int B = 6;
constexpr int K = 17;
constexpr int C = K - B;
constexpr int B2 = 1 << B;
constexpr int C2 = 1 << C;
constexpr int N = 1 << K;
constexpr int64_t INF = 1LL << 60;
vector<int> s[B2][C2][K + 1];
int a[K + 1];
vector<pair<int, int>> g[N];
int64_t d[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int k, m, S;
cin >> k >> m >> S;
for (int i = 1; i <= k; ++i)
cin >> a[i];
for (int i = 0; i < m; ++i) {
int u, v, w;
cin >> u >> v >> w;
g[u].emplace_back(v, w);
g[v].emplace_back(u, w);
}
const int n = 1 << k;
fill_n(d, n, INF);
for (int i = 0; i < B2; ++i) {
for (int j = 0; j < C2; ++j) {
for (int jj = 0; jj < C2; ++jj) {
int c = popcount(uint32_t(j) ^ uint32_t(jj));
s[i][j][c].push_back((i << C) + jj);
}
}
}
priority_queue<pair<int64_t, int>> pq;
pq.emplace(d[S] = 0, S);
while (not pq.empty()) {
auto [l, u] = pq.top();
pq.pop();
if (l != -d[u])
continue;
for (auto [v, w] : g[u]) {
if (d[u] + w < d[v]) {
pq.emplace(-(d[v] = d[u] + w), v);
}
}
const int j = u & (C2 - 1);
for (int i = 0; i < B2; ++i) {
for (int c = 0; c <= C; ++c) {
int cost = a[popcount(uint32_t(i) ^ uint32_t(u >> C)) + c];
for (int v : s[i][j][c]) {
if (d[u] + cost < d[v]) {
pq.emplace(-(d[v] = d[u] + cost), v);
}
}
s[i][j][c].clear();
}
}
}
for (int i = 0; i < n; ++i)
cout << d[i] << " \n"[i + 1 == n];
return 0;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
17 176734 32035 174241040 312806717 869838047 1051792036 618192507 729602782 144984364 904057367 922632751 676477964 651564213 314995751 370303789 14711019 7843270 941966995 532030000 50422 32035 12218 70235 32035 1913 84994 70235 27964 94874 84994 3469 32802 50422 6989 18176 32802 17541 91233 50422...
output:
104839 7871804 62870 66963 79027 7868957 77164 7858869 7869592 7863873 7863873 64039 51115 104082 70150 72482 57864 60745 69433 62907 88618 7858789 7881299 7872044 51092 68271 7855529 7881281 94531 87056 7877506 59789 80215 7863790 87126 74831 74335 62096 51671 68573 7863873 44764 7875532 7860660 14...