QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#169019 | #6659. 외곽 순환 도로 2 | Cyanmond | Compile Error | / | / | C++17 | 3.7kb | 2023-09-09 10:49:04 | 2023-09-09 10:49:06 |
Judging History
你现在查看的是测评时间为 2023-09-09 10:49:06 的历史记录
- [2023-09-09 10:49:06]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-09-09 10:49:04]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define per(i, l, r) for (int i = (r - 1); i >= (l); --i)
#define ALL(x) (x).begin(), (x).end()
void chmin(i64 &a, const i64 b) {
if (a > b) a = b;
}
using Dp = array<array<array<i64, 2>, 2>, 2>; // (root, l, r)
Dp trans(const Dp &l, const Dp &r, const i64 w, const i64 c) {
Dp ret;
rep (i, 0, 2)
rep (j, 0, 2)
rep (k, 0, 2) ret[i][j][k] = 1ll << 60;
rep (i1, 0, 2)
rep (j1, 0, 2)
rep (k1, 0, 2) {
rep (i2, 0, 2)
rep (j2, 0, 2)
rep (k2, 0, 2) {
const i64 bc = l[i1][j1][k1] + r[i2][j2][k2];
if (k1 != j2) {
if (i1 == i2) chmin(ret[i1][j1][k2], bc);
else chmin(ret[i1][j1][k2], bc + c);
}
if (i1 != i2) chmin(ret[i1][j1][1 - k2], bc + w);
chmin(ret[i1][j1][1 - k2], bc + w + c);
chmin(ret[i1][j1][k2], bc + w + c);
}
}
return ret;
}
long long place_police(vector<int> P, vector<long long> C, vector<long long> W) {
const int N = (int)P.size() + 1, K = (int)W.size();
vector<vector<pair<int, i64>>> Tree(N);
rep (i, 1, N) {
Tree[P[i - 1]].push_back({i, C[i - 1]});
}
vector<int> leaves;
rep (i, 0, N) {
if (Tree[i].empty()) {
leaves.push_back(i);
}
}
vector<pair<int, int>> range(N);
vector<int> dist(N);
auto dfs1 = [&](auto &&self, const int v, const int d) -> pair<int, int> {
dist[v] = d;
if (Tree[v].empty()) return range[v] = {v, v};
int l = N + 1, r = -1;
for (const auto &[t, c] : Tree[v]) {
const auto [lt, rt] = self(self, t, d + 1);
l = min(l, lt);
r = max(r, rt);
}
return range[v] = {l, r};
};
dfs1(dfs1, 0, 0);
// auto parity = [&](int a, int b) { return (dist[a] + dist[b]) & 1; };
vector<Dp> dp(N);
for (auto &v : dp) {
rep (i, 0, 2)
rep (j, 0, 2)
rep (k, 0, 2) v[i][j][k] = 1ll << 60;
}
auto dfs = [&](auto &&self, const int v) -> void {
if (Tree[v].empty()) {
dp[v][0][0][0] = dp[v][1][1][1] = 0;
return;
}
Dp d;
rep (i, 0, 2)
rep (j, 0, 2)
rep (k, 0, 2) d[i][j][k] = 1ll << 60;
i64 before = 0;
for (const auto &[t, c] : Tree[v]) {
self(self, t);
if (t == Tree[v][0].first) {
rep (i, 0, 2)
rep (j, 0, 2)
rep (k, 0, 2) {
chmin(d[i][j][k], dp[t][i][j][k]);
chmin(d[1 - i][j][k], dp[t][i][j][k] + c);
}
} else {
d = trans(d, dp[t], before, c);
}
const int ri = lower_bound(ALL(leaves), range[t].second) - leaves.begin();
const i64 w = W[ri];
before = w;
}
Dp d2;
rep (i, 0, 2)
rep (j, 0, 2)
rep (k, 0, 2) d2[1 - i][j][k] = d[i][j][k];
dp[v] = move(d2);
return;
};
dfs(dfs, 0);
i64 ans = 1ll << 60;
i64 w = W.back();
rep (i, 0, 2)
rep (j, 0, 2)
rep (k, 0, 2) {
ans = min(ans, dp[0][i][j][k] + (j == k ? w : 0));
}
return ans;
}
詳細信息
cc1plus: fatal error: implementer.cpp: No such file or directory compilation terminated.