#include <bits/stdc++.h>
#define MAXN 310
#define MOD 1000000007
#define lld long long
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
lld dp[MAXN][MAXN][MAXN];
pii idx[MAXN];
lld bt(lld x, lld y, lld z) {
if(dp[x][y][z] != -1) return dp[x][y][z];
dp[x][y][z] = 0;
if(x > 0 && y > 0 && z > 0) dp[x][y][z] += x*y*z*bt(x-1, y-1, z-1);
if(x > 0 && y > 1) dp[x][y][z] += x*y*(y-1)*bt(x, y-2, z);
if(x > 1 && z > 0) dp[x][y][z] += x*(x-1)*z*bt(x-2, y, z);
if(x > 1 && y > 0) dp[x][y][z] += x*(x-1)*y*bt(x-1, y-1, z+1);
if(z > 1) dp[x][y][z] += z*(y+1)*(z-1)*bt(x, y, z-2);
if(y > 0 && z > 0) dp[x][y][z] += z*(y+1)*y*bt(x+1, y-1, z-1);
if(x > 0 && z > 0) dp[x][y][z] += z*x*z*bt(x-1, y+1, z-1);
if(dp[x][y][z] >= MOD) dp[x][y][z] %= MOD;
return dp[x][y][z];
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int N, T; cin >> N >> T;
for(int x = 0; x < MAXN; x++) for(int y = 0; y < MAXN; y++) for(int z = 0; z < MAXN; z++) dp[x][y][z] = -1;
dp[0][0][0] = 1;
while(T--) {
for(int i = 0; i < MAXN; i++) idx[i] = {0, 0};
for(int p = 1; p <= 3; p++) {
for(int i = 1; i <= 2*N; i++) {
int x; cin >> x;
if(idx[x].fi != 0) idx[x].se = p;
else idx[x].fi = p;
}
}
int x = 0, y = 0, z = 0;
for(int i = 1; i <= 3*N; i++) {
if(idx[i] == make_pair(1, 2)) x++;
if(idx[i] == make_pair(2, 3)) y++;
if(idx[i] == make_pair(1, 3)) z++;
}
cout << bt(x, y, z) << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
128 ms |
233476 KB |
Output isn't correct |
2 |
Incorrect |
127 ms |
233672 KB |
Output isn't correct |
3 |
Incorrect |
129 ms |
233580 KB |
Output isn't correct |
4 |
Incorrect |
128 ms |
233580 KB |
Output isn't correct |
5 |
Incorrect |
134 ms |
233580 KB |
Output isn't correct |
6 |
Incorrect |
134 ms |
233580 KB |
Output isn't correct |
7 |
Incorrect |
139 ms |
233580 KB |
Output isn't correct |
8 |
Incorrect |
142 ms |
233580 KB |
Output isn't correct |
9 |
Incorrect |
153 ms |
233580 KB |
Output isn't correct |
10 |
Incorrect |
160 ms |
233580 KB |
Output isn't correct |