QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#308252 | #6645. 百合 | ckiseki# | WA | 591ms | 22768kb | C++20 | 2.1kb | 2024-01-19 19:51:28 | 2024-01-19 19:51:29 |
Judging History
answer
#pragma GCC optimize("Ofast")
#pragma GCC target("popcnt")
#include <bits/extc++.h>
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using MaxHeap = __gnu_pbds::priority_queue<T, greater<T>>;
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;
bool vis[B2][C2][K + 1];
vector<int> v[K + 1];
int a[K + 1];
vector<pair<int, int>> g[N];
int64_t d[N];
int state[N];
MaxHeap<pair<int64_t, int>>::point_iterator pqit[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)
v[popcount(uint32_t(i))].push_back(i);
MaxHeap<pair<int64_t, int>> pq;
pq.push({d[S] = 0, S});
state[S] = 2;
while (not pq.empty()) {
auto [l, u] = pq.top();
pq.pop();
state[u] = 2;
for (auto [v, w] : g[u]) {
if (d[u] + w < d[v]) {
if (state[v] == 0) {
state[v] = 1;
pqit[v] = pq.push({-(d[v] = d[u] + w), v});
} else if (state[v] == 1) {
pq.modify(pqit[v], {-(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) {
if (vis[i][j][c])
continue;
int cost = a[popcount(uint32_t(i) ^ uint32_t(u >> C)) + c];
for (int vp : v[c]) {
const int v = (i << C) + (j ^ vp);
if (d[u] + cost < d[v]) {
if (state[v] == 0) {
state[v] = 1;
pqit[v] = pq.push({-(d[v] = d[u] + cost), v});
} else if (state[v] == 1) {
pq.modify(pqit[v], {-(d[v] = d[u] + cost), v});
}
}
}
vis[i][j][c] = true;
}
}
}
for (int i = 0; i < n; ++i)
cout << d[i] << " \n"[i + 1 == n];
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 591ms
memory: 22768kb
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:
922632751 904057367 904057367 144984364 676477964 922632751 922632751 904057367 676477964 922632751 922632751 904057367 651564213 676477964 676477964 922632751 676477964 922632751 922632751 904057367 651564213 676477964 676477964 922632751 651564213 676477964 676477964 922632751 314995751 651564213 ...
result:
wrong answer 1st lines differ - expected: '104839 7871804 62870 66963 790...71 64588 7862477 7869833 105717', found: '922632751 904057367 904057367 ...4 922632751 922632751 904057367'