# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
854624 | Tenis0206 | Fishing Game (RMI19_fishing) | C++11 | 2072 ms | 37312 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int nmax = 100;
const int Mod = 1e9 + 7;
int n;
int dp[3 * nmax + 5][3 * nmax + 5][3 * nmax + 5];
pair<int,int> p[3 * nmax + 5];
void update(int ab, int ac, int bc, int a, int b, int c)
{
if(ab==0 && ac==2 && bc==0)
{
ab = 0;
}
int last_nr = ab + ac + bc;
int last_ab = ab;
int last_ac = ac;
if(a==2)
{
/// a da una comuna intre b si c
return;
}
if(b==3)
{
/// b da una comuna intre c si a
return;
}
if(c==1)
{
///
return;
}
int coef = 1;
if(ab + ac == 0)
{
if(a!=1)
{
return;
}
}
else
{
if(a==1)
{
coef = 1LL * coef * ab % Mod;
--ab;
}
else if(a==3)
{
coef = 1LL * coef * ac % Mod;
--ac;
++bc;
}
}
if(ab < 0 || ac < 0 || bc < 0)
{
return;
}
if(bc + ab == 0)
{
if(b!=1)
{
return;
}
}
else
{
if(b==1)
{
coef = 1LL * coef * ab % Mod;
--ab;
++ac;
}
else if(b==2)
{
coef = 1LL * coef * bc % Mod;
--bc;
}
}
if(ab < 0 || ac < 0 || bc < 0)
{
return;
}
if(ac + bc == 0)
{
if(c!=2)
{
return;
}
}
else
{
if(c==2)
{
coef = 1LL * coef * bc % Mod;
--bc;
++ab;
}
else if(c==3)
{
coef = 1LL * coef * ac % Mod;
--ac;
}
}
if(ab < 0 || ac < 0 || bc < 0)
{
return;
}
if(ab + ac + bc == last_nr)
{
return;
}
dp[ab + ac + bc][ab][ac] += 1LL * dp[last_nr][last_ab][last_ac] * coef % Mod;
dp[ab + ac + bc][ab][ac] %= Mod;
}
void solve_test()
{
for(int i=1; i<=2*n; i++)
{
int x;
cin>>x;
if(!p[x].first)
{
p[x].first = 1;
}
else
{
p[x].second = 1;
}
}
for(int i=1; i<=2*n; i++)
{
int x;
cin>>x;
if(!p[x].first)
{
p[x].first = 2;
}
else
{
p[x].second = 2;
}
}
for(int i=1; i<=2*n; i++)
{
int x;
cin>>x;
if(!p[x].first)
{
p[x].first = 3;
}
else
{
p[x].second = 3;
}
}
int nr_tot = 3 * n;
int nrab = 0, nrac = 0;
for(int i=1; i<=3*n; i++)
{
if(p[i].first==p[i].second)
{
--nr_tot;
continue;
}
if(p[i].first==1 && p[i].second==2)
{
++nrab;
}
else if(p[i].first==1 && p[i].second==3)
{
++nrac;
}
}
dp[nr_tot][nrab][nrac] = 1;
for(int nr=nr_tot; nr>=1; nr--)
{
for(int ab=0; ab<=nr; ab++)
{
for(int ac=0; ab+ac<=nr; ac++)
{
int bc = nr - ab - ac;
for(int a=1; a<=3; a++)
{
for(int b=1; b<=3; b++)
{
for(int c=1; c<=3; c++)
{
update(ab,ac,bc,a,b,c);
}
}
}
}
}
}
cout<<dp[0][0][0]<<'\n';
for(int nr=nr_tot;nr>=0;nr--)
{
for(int ab=0;ab<=nr;ab++)
{
for(int ac=0;ab+ac<=nr;ac++)
{
dp[nr][ab][ac] = 0;
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef home
freopen("nr.in","r",stdin);
freopen("nr.out","w",stdout);
#endif // home
int t;
cin>>n>>t;
for(int i=1; i<=t; i++)
{
solve_test();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |