QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#308252#6645. 百合ckiseki#WA 591ms22768kbC++202.1kb2024-01-19 19:51:282024-01-19 19:51:29

Judging History

你现在查看的是最新测评结果

  • [2024-01-19 19:51:29]
  • 评测
  • 测评结果:WA
  • 用时:591ms
  • 内存:22768kb
  • [2024-01-19 19:51:28]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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'