QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133947 | #4938. Writing Tasks | Rd_rainydays | WA | 8ms | 59976kb | C++20 | 3.0kb | 2023-08-02 17:53:27 | 2023-08-02 17:54:18 |
Judging History
answer
#include <bits/stdc++.h>
using std::vector;
using std::tuple;
#define all(x) (x).begin(), (x).end()
const int N = 400005;
int A, C, T;
vector<int> L[N], F[N], S[N], ps[N];
int tot;
vector<int> adj[N];
std::map<tuple<int, int>, int> id;
vector<int> vs[N];
bool vis[N];
void solve() {
for (int i = 1; i <= tot; i++)
assert(adj[i].size() <= 2u);
vector<int> ids;
bool isRing = 0;
auto dfs = [&](int x, int f, auto& dfs) -> void {
ids.push_back(x);
vis[x] = 1;
for (auto y : adj[x]) if (y != f) {
if (vis[y] == 1) { isRing = 1; break; }
dfs(y, x, dfs);
}
};
int ans = 0;
for (int i = 1; i <= tot; i++) {
if (vis[i]) continue;
isRing = 0;
ids.clear();
dfs(i, 0, dfs);
vector<std::array<int, 3>> dp(ids.size());
auto do_trans = [&](int exclude) -> int {
for (int j = 1; j < (int)ids.size(); j++) {
int cur = ids[j], pre = ids[j - 1];
for (int t = 0; t < (int)vs[cur].size(); t++)
dp[j][t + 1] = dp[j - 1][0] + 1;
dp[j][0] = *std::max_element(all(dp[j - 1]));
// trivial
for (int t = 0; t < (int)vs[cur].size(); t++)
for (int s = 0; s < (int)vs[pre].size(); s++) {
if (vs[cur][t] == vs[pre][s]) continue;
dp[j][t] = std::max(dp[j][t], dp[j - 1][s] + 1);
}
}
int cur_ans = 0;
for (int i = 0; i < 3; i++) {
if (i == exclude && exclude > 0) continue;
cur_ans = std::max(cur_ans, dp.back()[i]);
}
return cur_ans;
};
if (!isRing) {
dp.assign(ids.size(), {0, 0, 0});
dp[0][0] = 0;
for (int t = 0; t < (int)vs[ids[0]].size(); t++)
dp[0][t + 1] = 1;
ans += do_trans(0);
} else {
vector<int> cadi;
for (int ex = 0; ex <= vs[ids[0]].size(); ex++) {
dp.assign(ids.size(), {0, 0, 0});
dp[0][ex] = (ex > 0);
cadi.push_back(do_trans(ex));
}
ans += *std::max_element(all(cadi));
}
}
printf("%d\n", ans);
return;
}
int main() {
scanf("%d%d%d", &A, &C, &T);
for (int i = 1; i <= A; i++) {
int sz;
scanf("%d", &sz);
L[i].resize(sz);
for (auto &x : L[i]) scanf("%d", &x);
}
for (int i = 1; i <= A; i++) {
int sz;
scanf("%d", &sz);
F[i].resize(sz);
for (auto &x : F[i]) scanf("%d", &x);
}
for (int i = 1; i <= C; i++) {
int sz;
scanf("%d", &sz);
S[i].resize(sz);
for (auto &x : S[i]) {
scanf("%d", &x);
++tot;
ps[x].push_back(tot);
id[{i, x}] = tot;
}
if (sz == 2) {
adj[tot].push_back(tot - 1);
adj[tot - 1].push_back(tot);
}
}
for (int i = 1; i <= T; i++)
if ((int)ps[i].size() == 2) {
adj[ps[i][0]].push_back(ps[i][1]);
adj[ps[i][1]].push_back(ps[i][0]);
}
for (int i = 1; i <= A; i++)
for (auto l : L[i]) for (auto f : F[i])
vs[id[{l, f}]].push_back(i);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 8ms
memory: 59976kb
input:
2 3 2 2 1 2 2 2 3 1 1 1 1 1 1 1 1 1 2
output:
1
result:
wrong answer 1st lines differ - expected: '2', found: '1'