#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(x < 0 || y < 0 || z < 0) return 0;
if(dp[x][y][z] != -1) return dp[x][y][z];
dp[x][y][z] = 0;
dp[x][y][z] += x*y*z*bt(x-1, y-1, z-1);
dp[x][y][z] += x*y*(y-1)*bt(x, y-2, z);
dp[x][y][z] += x*(x-1)*z*bt(x-2, y, z);
dp[x][y][z] += x*(x-1)*y*bt(x-1, y-1, z+1);
dp[x][y][z] += z*(y+1)*(z-1)*bt(x, y, z-2);
dp[x][y][z] += z*(y+1)*y*bt(x+1, y-1, z-1);
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 |
233580 KB |
Output isn't correct |
2 |
Incorrect |
128 ms |
233580 KB |
Output isn't correct |
3 |
Incorrect |
128 ms |
233580 KB |
Output isn't correct |
4 |
Incorrect |
131 ms |
233580 KB |
Output isn't correct |
5 |
Incorrect |
135 ms |
233580 KB |
Output isn't correct |
6 |
Incorrect |
141 ms |
233580 KB |
Output isn't correct |
7 |
Incorrect |
144 ms |
233580 KB |
Output isn't correct |
8 |
Incorrect |
151 ms |
233472 KB |
Output isn't correct |
9 |
Incorrect |
191 ms |
233580 KB |
Output isn't correct |
10 |
Incorrect |
170 ms |
233580 KB |
Output isn't correct |