#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MOD = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 210;
const ll BSIZ= 800;
int dp[MAXN][MAXN][MAXN][3][2];
int N,T,a,b;
set<int> S[MAXN];
void rdin(int x){
cin>>a;
if(S[x].find(a)!=S[x].end())S[x].erase(a);
else S[x].insert(a);
}
int ask(int ab,int ac,int bc,int turn,int used){
if(min({ab,ac,bc})<0)return 0;
if(dp[ab][ac][bc][turn][used]!=-1)return dp[ab][ac][bc][turn][used];
if(ab==0&&ac==0&&bc==0)return dp[ab][ac][bc][turn][used]=1;
int ans=0;
if(turn==0){
// a is moving to b, can either move one of ab and one of ac
ans+=ab*ask(ab-1,ac,bc,1,1);
ans+=ac*ask(ab,ac-1,bc+1,1,used);
}else if(turn==1){
ans+=bc*ask(ab,ac,bc-1,2,1);
ans+=ab*ask(ab-1,ac+1,bc,2,used);
}else{
ans+=ac*ask(ab,ac-1,bc,0,0);
if(used){
ans+=bc*ask(ab+1,ac,bc-1,0,0);
}
}
return dp[ab][ac][bc][turn][used]=ans;
}
int main(){
cin>>N>>T;
memset(dp,-1,sizeof(dp));
while(T--){
for(int i=0;i<3;++i)S[i].clear();
for(int i=0;i<2*N;++i){rdin(0);}
for(int i=0;i<2*N;++i){rdin(1);}
for(int i=0;i<2*N;++i){rdin(2);}
int ab=0;
int ac=0;
int bc=0;
for(auto i:S[0])for(auto j:S[1])if(i==j)++ab;
for(auto i:S[0])for(auto j:S[2])if(i==j)++ac;
for(auto i:S[1])for(auto j:S[2])if(i==j)++bc;
cout<<ask(ab,ac,bc,0,0)<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
112 ms |
217848 KB |
Output isn't correct |
2 |
Incorrect |
114 ms |
217848 KB |
Output isn't correct |
3 |
Incorrect |
111 ms |
217848 KB |
Output isn't correct |
4 |
Incorrect |
113 ms |
217852 KB |
Output isn't correct |
5 |
Incorrect |
128 ms |
217844 KB |
Output isn't correct |
6 |
Incorrect |
132 ms |
217848 KB |
Output isn't correct |
7 |
Incorrect |
145 ms |
217848 KB |
Output isn't correct |
8 |
Incorrect |
162 ms |
217848 KB |
Output isn't correct |
9 |
Incorrect |
184 ms |
217976 KB |
Output isn't correct |
10 |
Incorrect |
213 ms |
217848 KB |
Output isn't correct |