QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116129#6659. 외곽 순환 도로 2hos_lyric#Compile Error//C++145.7kb2023-06-28 10:13:102024-05-31 18:18:10

Judging History

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

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

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


namespace sub3 {
Int dp[MAX_N][2];
void run() {
  for (int u = N; --u >= 0; ) {
    if (~ks[u]) {
      const int x = 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;
        }
      }
    }
  }
  ans = min(dp[0][0], dp[0][1]);
}
}  // sub3


namespace sub6 {
#define rep2(i) for (int i = 0; i < 2; ++i)
Int dp[MAX_N][2][2][2];
void run() {
  vector<int> ls(N, -1), rs(N, -1);
  for (int u = N; --u >= 0; ) {
    if (~ks[u]) {
      ls[u] = rs[u] = ks[u];
      rep2(x) rep2(a) rep2(b) {
        dp[u][x][a][b] = INF;
      }
      rep2(x) {
        dp[u][x][x][x] = 0;
      }
    } else {
      Int crt[2][2][2];
      rep2(x) rep2(a) rep2(b) {
        crt[x][a][b] = INF;
      }
      for (const int v : graph[u]) {
        if (v == graph[u][0]) {
          rep2(x) {
            rep2(y) rep2(c) rep2(d) {
              chmin(crt[x][c][d],
                    ((x == y) ? C[v - 1] : 0)
                    + dp[v][y][c][d]);
            }
          }
          ls[u] = ls[v];
          rs[u] = rs[v];
        } else {
          Int nxt[2][2][2];
          rep2(x) rep2(a) rep2(b) {
            nxt[x][a][b] = INF;
          }
          rep2(x) rep2(a) rep2(b) {
            rep2(y) rep2(c) rep2(d) {
              chmin(nxt[x][a][d],
                    crt[x][a][b]
                    + ((x == y) ? C[v - 1] : 0)
                    + ((b == c) ? W[rs[u]] : 0)
                    + dp[v][y][c][d]);
            }
          }
          memcpy(crt, nxt, sizeof(nxt));
          rs[u] = rs[v];
        }
      }
      memcpy(dp[u], crt, sizeof(crt));
    }
  }
// cerr<<"ls = "<<ls<<endl;
// cerr<<"rs = "<<rs<<endl;
  rep2(x) rep2(a) rep2(b) {
    chmin(ans, dp[0][x][a][b] + ((a == b) ? W[K - 1] : 0));
  }
}
#undef rep2
}  // sub6

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;
  }
// cerr<<"leafs = "<<leafs<<endl;
  
  ans = INF;
  
  bool special = true;
  for (int i = 0; i < N - 1; ++i) special = special && (C[i] <= 1'000'000);
  for (int k = 0; k < K; ++k) special = special && (W[k] == 1'000'000'000'000LL);
  
/*
  if (K <= 5) {
    sub1::run();
  } else if (P == vector<int>(N - 1, 0)) {
    sub2::run();
  } else if (special && K % 2 == 0) {
    sub3::run();
  }
*/
  sub6::run();
  return ans;
}

详细

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