QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116110#6659. 외곽 순환 도로 2hos_lyric#Compile Error//C++143.4kb2023-06-28 09:49:582024-05-31 14:20:41

Judging History

你现在查看的是测评时间为 2024-05-31 14:20:41 的历史记录

  • [2024-08-26 15:49:29]
  • 管理员手动重测本题所有提交记录
  • 测评结果:14
  • 用时:27ms
  • 内存:14704kb
  • [2024-05-31 14:20:41]
  • 评测
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-28 09:49:58]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


constexpr int MAX_N = 100'010;
constexpr Int INF = 1001001001001001001LL;

int N, K;
vector<int> P;
vector<Int> C, W;

vector<vector<int>> graph;
vector<int> leafs;
vector<int> ks;

Int ans;


namespace sub2 {
void run() {
  assert(K == N - 1);
  // 0: same color as root
  for (int s = 0; s < 2; ++s) {
    Int crt[2] = {INF, INF};
    crt[s] = (0 == s) ? C[0] : 0;
    for (int i = 1; i < K; ++i) {
      Int nxt[2] = {INF, INF};
      for (int x = 0; x < 2; ++x) for (int y = 0; y < 2; ++y) {
        chmin(nxt[y], crt[x] + ((x == y) ? W[i - 1] : 0) + ((0 == y) ? C[i] : 0));
      }
      copy(nxt, nxt + 2, crt);
    }
    for (int x = 0; x < 2; ++x) {
      chmin(ans, crt[x] + ((x == s) ? W[K - 1] : 0));
    }
  }
}
}  // sub2


namespace sub1 {
Int dp[MAX_N][2];
void run() {
  for (int p = 0; p < 1 << K; ++p) {
    for (int u = N; --u >= 0; ) {
      if (~ks[u]) {
        const int x = p >> ks[u] & 1;
        dp[u][x] = 0;
        dp[u][x ^ 1] = INF;
      } else {
        fill(dp[u], dp[u] + 2, 0);
        for (const int v : graph[u]) {
          for (int x = 0; x < 2; ++x) {
            Int mn = INF;
            for (int y = 0; y < 2; ++y) {
              chmin(mn, ((x == y) ? C[v - 1] : 0) + dp[v][y]);
            }
            dp[u][x] += mn;
          }
        }
      }
    }
    Int cost = min(dp[0][0], dp[0][1]);
    for (int k = 0; k < K; ++k) {
      if ((p >> k & 1) == (p >> ((k+1)%K) & 1)) {
        cost += W[k];
      }
    }
    chmin(ans, cost);
  }
}
}  // sub1


long long place_police(vector<int> P_, vector<long long> C_, vector<long long> W_) {
  P = P_;
  C = C_;
  W = W_;
  N = (int)P.size() + 1;
  K = W.size();
  
  graph.assign(N, {});
  for (int i = 0; i < N - 1; ++i) {
    graph[P[i]].push_back(i + 1);
  }
  for (int u = 1; u < N; ++u) if (graph[u].empty()) {
    leafs.push_back(u);
  }
  assert((int)leafs.size() == K);
  ks.assign(N, -1);
  for (int k = 0; k < K; ++k) {
    ks[leafs[k]] = k;
  }
  
  ans = INF;
  
#ifdef LOCAL
  if (K <= 6) {
#else
  if (K <= 5) {
#endif
    sub1::run();
  } else if (P == vector<int>(N - 1, 0)) {
    sub2::run();
  }
  return ans;
}

详细

cc1plus: fatal error: implementer.cpp: No such file or directory
compilation terminated.