#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 1000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define single_case solve();
#define line cerr<<"----------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); }
#define mod 1000000007LL
const int N = 305;
ll dp[N][N][N];
ll a[N], b[N], c[N];
ll resi(ll x, ll y, ll z)
{
//cout<<x<<" "<<y<<" "<<z<<endl;
if(x<0||y<0||z<0) return 0;
if(dp[x][y][z]!=-1) return dp[x][y][z];
dp[x][y][z] = (z*x*z*resi(x-1, y+1, z-1))%mod;
dp[x][y][z] = (dp[x][y][z] + z*(y+1)*y*resi(x+1, y-1, z-1))%mod;
dp[x][y][z] = (dp[x][y][z] + x*(x-1)*y*resi(x-1, y-1, z+1))%mod;
dp[x][y][z] = (dp[x][y][z] + x*y*(y-1)*resi(x, y-2, z))%mod;
dp[x][y][z] = (dp[x][y][z] + x*(x-1)*(z+1)*resi(x-2, y, z))%mod;
dp[x][y][z] = (dp[x][y][z] + z*(y+1)*(z-1)*resi(x, y, z-2))%mod;
dp[x][y][z] = (dp[x][y][z] + x*y*z*resi(x-1, y-1, z-1))%mod;
return dp[x][y][z];
}
int main()
{
ios
ll n, t;
cin>>n>>t;
for(int i = 0;i<N;i++)for(int j = 0;j<N;j++)for(int z = 0;z<N;z++) dp[i][j][z] = -1LL;
dp[0][0][0] = 1;
while(t--)
{
//for(int i = 0;i<3*n+2;i++)for(int j = 0;j<3*n+2;j++)for(int z = 0;z<3*n+2;z++) dp[i][j][z] = -1;
for(int i = 0;i<N;i++) a[i] = b[i] = c[i] = 0;
for(int i = 0;i<2*n;i++)
{
ll x;
cin>>x;
a[x]++;
}
for(int i = 0;i<2*n;i++)
{
ll x;
cin>>x;
b[x]++;
}
for(int i = 0;i<2*n;i++)
{
ll x;
cin>>x;
c[x]++;
}
ll x, y, z;
x = y = z = 0;
for(int i = 1;i<=3*n;i++) if(a[i]&&b[i]) x++;
for(int i = 1;i<=3*n;i++) if(b[i]&&c[i]) y++;
for(int i = 1;i<=3*n;i++) if(a[i]&&c[i]) z++;
cout<<resi(x, y, z)<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
128 ms |
222376 KB |
Output isn't correct |
2 |
Incorrect |
127 ms |
222444 KB |
Output isn't correct |
3 |
Incorrect |
125 ms |
222444 KB |
Output isn't correct |
4 |
Incorrect |
126 ms |
222548 KB |
Output isn't correct |
5 |
Incorrect |
132 ms |
222424 KB |
Output isn't correct |
6 |
Incorrect |
137 ms |
222444 KB |
Output isn't correct |
7 |
Incorrect |
148 ms |
222572 KB |
Output isn't correct |
8 |
Incorrect |
151 ms |
222444 KB |
Output isn't correct |
9 |
Incorrect |
162 ms |
222532 KB |
Output isn't correct |
10 |
Incorrect |
174 ms |
222444 KB |
Output isn't correct |