1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include<bits/stdc++.h> #define LL long long using namespace std; template <class T> inline void read(T &res) { res = 0; bool flag = 0; char c = getchar(); while('0' > c || c > '9') {if(c == '-') flag = 1; c = getchar();} while('0' <= c && c <= '9') res = (res << 3) + (res << 1) + (c ^ 48), c= getchar(); if(flag) res = -res; } template <class T, class ...Arg> inline void read(T &res, Arg &...com){ read(res), read(com...);} template <class T> void write(T res) { if(res > 9) write(res / 10); putchar(res % 10 + '0'); } const int N = 1e4 + 5, M = 5e4 + 5, mod = 998244353; int n, c; int num[M][32]; inline void init() { for(int i = 1, fear, like, st, lk, dk;i <= c;i ++) { fear = like = 0; read(st, dk, lk); for(int j = 1, a;j <= dk;j ++) read(a), a = (a - st + n) % n, fear |= 1 << a; for(int j = 1, a;j <= lk;j ++) read(a), a = (a - st + n) % n, like |= 1 << a; for(int j = 0;j <= 31;j ++) if(((fear & j) < fear) || ((like & j) != 0)) num[st][j] ++; } } int f[M][32], ans; int main() { read(n, c); init(); for(int i = 0;i < 32;i ++) { memset(f[0], 128, sizeof(f[0])); f[0][i] = 0; for(int j = 1;j <= n;j ++) for(int k = 0;k < 32;k ++) f[j][k] = max(f[j - 1][(k & 15) << 1], f[j - 1][(k & 15) << 1 | 1]) + num[j][k]; ans = max(ans, f[n][i]); } write(ans); return 0; }
|