QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133955 | #4938. Writing Tasks | Rd_rainydays | RE | 8ms | 60016kb | C++20 | 4.0kb | 2023-08-02 18:19:10 | 2023-08-02 18:19:12 |
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<tuple<int, int>> es;
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;
int head = -1;
auto dfs = [&](int x, int f, auto& dfs) -> void {
ids.push_back(x);
// printf(" dfs log : %d\n", x);
vis[x] = 1;
if (adj[x].size() == 1u) head = x;
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, head = -1;
ids.clear();
dfs(i, 0, dfs);
if (head != -1 && isRing) std::reverse(ids.begin(), std::find(all(ids), head) + 1);
if (isRing) throw;
// printf(" %s :", (isRing ? "Ring" : "Chain"));
// for (int id : ids)
// printf(" %d ", id);
// puts("");
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 + 1] = std::max(dp[j][t + 1], dp[j - 1][s + 1] + 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 <= (int)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);
}
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)
es.emplace_back(tot - 1, tot);
}
for (int i = 1; i <= T; i++)
if ((int)ps[i].size() == 2)
es.emplace_back(ps[i][0], ps[i][1]);
for (int i = 1; i <= A; i++)
for (auto l : L[i]) for (auto f : F[i])
if (id.count({l, f}))
vs[id[{l, f}]].push_back(i);
for (auto &[a, b] : es)
if (a > b) std::swap(a, b);
std::sort(all(es));
es.erase(std::unique(all(es)), es.end());
for (auto [a, b] : es) {
adj[a].push_back(b);
adj[b].push_back(a);
}
solve();
return 0;
}
/*
15 15 20
2 12 14
2 1 3
1 11
2 5 13
2 8 9
1 13
1 9
2 15 11
2 3 6
2 6 7
1 10
1 2
2 7 12
1 14
1 4
1 3
1 1
2 12 20
2 18 2
2 10 15
2 2 10
2 15 18
2 17 3
2 6 7
2 16 17
1 19
2 13 6
1 14
2 4 11
2 8 16
2 1 4
1 13
2 6 1
1 8
1 18
2 16 7
1 14
2 10 11
2 15 19
2 19 18
1 12
1 3
1 2
2 4 16
2 17 15
2 3 2
2 1 2
2 2 3
1 1
1 1
1 1
1 1
1 2
3 4 3
1 2
2 4 2
2 1 3
1 1
2 2 3
2 3 2
1 3
2 1 3
1 2
1 2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 59980kb
input:
2 3 2 2 1 2 2 2 3 1 1 1 1 1 1 1 1 1 2
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 8ms
memory: 60016kb
input:
2 2 2 0 1 2 0 2 1 2 2 1 2 0
output:
0
result:
ok single line: '0'
Test #3:
score: -100
Dangerous Syscalls
input:
40623 39265 42226 2 14643 37432 2 29610 20181 2 6441 7614 2 17559 3238 2 39001 17644 2 6431 37097 2 6347 12246 2 1130 1688 2 38583 9078 2 8746 27832 2 13090 39048 2 32647 18777 2 27505 19277 2 31201 25824 2 6133 20344 2 11625 20997 2 18528 35730 0 2 22986 5273 2 10942 38791 2 19025 35679 2 32321 124...