0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-14 16:38:46 +00:00
OI-codes/Luogu/P3622/P3622.cpp

60 lines
1.2 KiB
C++
Raw Normal View History

#include <iostream>
#include <algorithm>
#include <limits>
using namespace std;
const int N = 1e4 + 5,
C = 5e4 + 5,
M = (1 << 5) + 5;
int n, c, a[C][M], f[N][M], ans;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> c;
for (int i = 1, e, f, l; i <= c; i++) {
cin >> e >> f >> l;
int fear = 0;
for (int j = 1, x; j <= f; j++) {
cin >> x;
fear |= (1 << (x - e + n) % n);
}
int like = 0;
for (int j = 1, y; j <= l; j++) {
cin >> y;
like |= (1 << (y - e + n) % n);
}
for (int j = 0; j < 1 << 5; j++) {
if ((like & j) || (fear & ~j)) a[e][j]++;
}
}
for (int s = 0; s < 1 << 5; s++) {
std::fill_n(f[0], M, std::numeric_limits<int>::min());
f[0][s] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 1 << 5; j++) {
f[i][j] = max(f[i - 1][(j & 0b1111) << 1], f[i - 1][(j & 0b1111) << 1 | 1]) + a[i][j];
}
}
ans = std::max(ans, f[n][s]);
}
cout << ans << endl;
return 0;
}