QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#250259#7185. Poor Studentskilo_tobo_tarjen#Compile Error//C++142.7kb2023-11-13 00:36:142023-11-13 00:36:14

Judging History

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

  • [2023-11-13 00:36:14]
  • 评测
  • [2023-11-13 00:36:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const char el = '\n';
typedef long long ll;
int k;
typedef array<ll, 10> box;
vector<box> a;
ll dist(box &a, int u, int v) { return a[v] - a[u]; }
const ll inf = 1e18;
struct graph {
  vector<vector<set<pair<ll, int>>>> bxst;
  vector<int> lim;
  graph(int n) : bxst(n, vector(n, set<pair<ll, int>>())), lim(n + 1) {
    lim.back() = 1;
  }
  pair<ll, int> edge(int u, int v) {
    auto &st = bxst[u][v];
    return st.size() ? *st.begin() : pair<ll, int>{inf, -1};
  }
  ll val(int u, int v) { return edge(u, v).first; }
  ll id(int u, int v) { return edge(u, v).second; }
  vector<ll> dis;
  vector<int> pre;
  pair<vector<int>, ll> spfa(vector<vector<ll>> &e) {
    dis.assign(k + 1, inf);
    pre.assign(k + 1, 0);
    vector<bool> inque(k + 1);
    queue<int> que;
    dis[k] = 0;
    que.push(k);
    inque[k] = true;
    while (que.size()) {
      int u = que.front();
      que.pop();
      inque[u] = false;
      for (int v = 0; v < k; v++)
        if (dis[v] > dis[u] + e[u][v]) {
          dis[v] = dis[u] + e[u][v];
          pre[v] = u;
          if (!inque[v]) {
            que.push(v);
            inque[v] = true;
          }
        }
    }
    int p = -1;
    for (int i = 0; i < k; i++)
      if (lim[i]) {
        if (!~p) p = i;
        if (dis[i] < dis[p]) p = i;
      }
    ll disp = dis[p];
    vector<int> res = {p};
    while (p != k) res.push_back(p = pre[p]);
    reverse(res.begin(), res.end());
    return {res, disp};
  }
  void delbox(int u, int x) {
    for (int v = 0; v < k; v++) bxst[u][v].erase({dist(a[x], u, v), x});
  }
  void addbox(int u, int x) {
    for (int v = 0; v < k; v++) bxst[u][v].insert({dist(a[x], u, v), x});
  }
  ll solve(int x) {
    vector e(k + 1, vector<ll>(k + 1, inf));
    for (int i = 0; i < k; i++) e[k][i] = a[x][i];
    for (int i = 0; i < k; i++)
      for (int j = 0; j < k; j++) e[i][j] = val(i, j);
    // for (auto arr : e) {
    //   for (auto v : arr) cout << v << ' ';
    //   cout << el;
    // }
    // cout << el;
    auto [p, res] = spfa(e);
    vector<int> b = {x};
    for (int i = 2; i < p.size(); i++) b.push_back(id(p[i - 1], p[i]));
    for (int i = 1; i < p.size() - 1; i++) delbox(p[i], b[i]);
    for (int i = 1; i < p.size(); i++) addbox(p[i], b[i - 1]);
    lim[p.back()]--;
    return res;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(15);
  int n;
  cin >> n >> k;
  graph g(k);
  a.resize(n);
  for (auto &arr : a)
    for (int i = 0; i < k; i++) cin >> arr[i];
  for (int i = 0; i < k; i++) cin >> g.lim[i];
  ll ans = 0;
  for (int i = 0; i < n; i++) ans += g.solve(i);
  cout << ans << el;
  return 0;
}

Details

answer.code: In constructor ‘graph::graph(int)’:
answer.code:13:32: error: missing template arguments before ‘(’ token
   13 |   graph(int n) : bxst(n, vector(n, set<pair<ll, int>>())), lim(n + 1) {
      |                                ^
answer.code: In member function ‘ll graph::solve(int)’:
answer.code:65:12: error: missing template arguments before ‘e’
   65 |     vector e(k + 1, vector<ll>(k + 1, inf));
      |            ^
answer.code:66:33: error: ‘e’ was not declared in this scope
   66 |     for (int i = 0; i < k; i++) e[k][i] = a[x][i];
      |                                 ^
answer.code:68:35: error: ‘e’ was not declared in this scope
   68 |       for (int j = 0; j < k; j++) e[i][j] = val(i, j);
      |                                   ^
answer.code:74:10: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’
   74 |     auto [p, res] = spfa(e);
      |          ^
answer.code:74:26: error: ‘e’ was not declared in this scope
   74 |     auto [p, res] = spfa(e);
      |                          ^