题解 | #Jobs (Easy Version)#
Jobs (Easy Version)
https://ac.nowcoder.com/acm/contest/33189/D
D Jobs (Easy Version)
bitset邪教,优雅的暴力三维前缀或,完全不需要脑子!来自队友的提交+我修改数组大小。极限卡过空间以及优美的时间(什么?我是全队唯一的单身狗?)。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
uniform_int_distribution<> u(1,400);
const int N = 15, M = 401, mod = 998244353;
bitset<10> s[M][M][M];
int n, m, seed;
LL qmi(LL a, LL b){
LL res = 1;
while(b){
if(b & 1) res = res * a % mod;
b >>= 1;
a = a * a % mod;
}
return res;
}
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i ++){
int k;
cin >> k;
while(k --){
int a, b, c;
cin >> a >> b >> c;
s[a][b][c][i] = true;
}
}
cin >> seed;
mt19937 rng(seed);
for(int j = 1; j <= 400; j ++){
for(int k = 1; k <= 400; k ++){
for(int l = 1; l <= 400; l ++){
s[j][k][l] = (s[j][k][l] | s[j - 1][k - 1][l - 1] | s[j - 1][k - 1][l] | s[j - 1][k][l - 1]
| s[j][k - 1][l - 1] | s[j - 1][k][l] | s[j][k - 1][l] | s[j][k][l - 1]);
}
}
}
int lastans=0, res = 0;
for (int i=1;i<=m;i++){
int IQ=(u(rng)^lastans)%400+1; // The IQ of the i-th friend
int EQ=(u(rng)^lastans)%400+1; // The EQ of the i-th friend
int AQ=(u(rng)^lastans)%400+1; // The AQ of the i-th friend
int temp = s[IQ][EQ][AQ].count();
res = (res + (temp * qmi(seed, m - i)) % mod) % mod;
lastans = temp; // The answer to the i-th friend
}
cout << res << endl;
return 0;
}