# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1063043 | AKaan37 | Fishing Game (RMI19_fishing) | C++17 | 275 ms | 524288 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;
typedef long long int lo;
//~ #define int long long
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n*2;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const int li = 301;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flagt,t,dp[li][li][li][3][2];
int cev;
//~ map<PIIIII,int> dp;
inline int add(int x,int y){
if(x+y>=mod)return x+y-mod;
return x+y;
}
inline int mul(lo x,lo y){
return (x%mod)*(y%mod)%mod;
}
inline int f(int x,int y,int z,int kim,int last){
int cevv=0;
if(x==0 && y==0 && z==0)return 1;
if(dp[x][y][z][kim][last]!=-1)return dp[x][y][z][kim][last];
if(kim==0){
if(x==0 && z==0)cevv=add(cevv,f(x,y,z,1,0));
if(x)cevv=add(cevv,mul(x,f(x-1,y,z,1,1)));
if(z)cevv=add(cevv,mul(z,f(x,y+1,z-1,1,0)));
}
if(kim==1){
if(y==0 && x==0)cevv=add(cevv,f(x,y,z,2,last));
if(y)cevv=add(cevv,mul(y,f(x,y-1,z,2,1)));
if(x)cevv=add(cevv,mul(x,f(x-1,y,z+1,2,last)));
}
if(kim==2){
if(z)cevv=add(cevv,mul(z,f(x,y,z-1,0,0)));
if(last && y)cevv=add(cevv,mul(y,f(x+1,y-1,z,0,0)));
}
return dp[x][y][z][kim][last]=cevv;
}
int32_t main(void){
scanf("%d %d",&n,&t);
memset(dp,-1,sizeof(dp));
while(t--){
FOR{
scanf("%d",&a[i]);
}
FOR{
scanf("%d",&b[i]);
}
int aveb=0,avec=0,bvec=0;
FOR{
int oku;
scanf("%d",&oku);
for(int j=1;j<=n*2;j++){
if(oku==a[j])avec++;
if(oku==b[j])bvec++;
}
}
FOR{
for(int j=1;j<=n*2;j++){
if(a[i]==b[j])aveb++;
}
}
printf("%d\n",f(aveb,bvec,avec,0,0));
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |