QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#308301 | #6645. 百合 | ckiseki | WA | 786ms | 31936kb | C++20 | 1.7kb | 2024-01-19 20:53:09 | 2024-01-19 20:53:11 |
Judging History
answer
#pragma GCC optimize("Ofast")
#pragma GCC target("popcnt")
#include <bits/extc++.h>
#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> vv[C2];
bool vis[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 < C2; ++i)
vv[popcount(uint32_t(i))].push_back(i);
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) {
const int ll = popcount(uint32_t(i) ^ uint32_t(u >> C)) + c;
if (vis[i][j][ll])
continue;
int cost = a[ll];
for (int vp : vv[c]) {
const int v = (i << C) + (j ^ vp);
if (v >= n)
continue;
if (d[u] + cost < d[v]) {
pq.emplace(-(d[v] = d[u] + cost), v);
}
}
vis[i][j][ll] = true;
}
}
}
for (int i = 0; i < n; ++i)
cout << d[i] << " ";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 786ms
memory: 31936kb
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 78...
result:
wrong answer 59th numbers differ - expected: '7882394', found: '14723278'