# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
207159 | mayhoubsaleh | Fishing Game (RMI19_fishing) | C++14 | 589 ms | 129016 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>
#include <string>
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int mod=1e9+7;
int n;
int dp[3][222][222][222];
map<int,int>m[3];
int cnt[3];
int sz[3];
int f(int pl,int cnt[],int sz[]){
int &ans=dp[pl][cnt[0]][cnt[1]][cnt[2]];
if(ans+1)return ans;
ans=0;
if(!sz[pl])return ans=1;
if(cnt[pl]){
cnt[pl]--;
sz[pl]--;
sz[(pl+1)%3]--;
ans=(ans+(cnt[pl]+1)*f((pl+1)%3,cnt,sz)%mod)%mod;
sz[(pl+1)%3]++;
sz[pl]++;
cnt[pl]++;
}
if(sz[pl]-cnt[pl]){
int x=sz[pl]-cnt[pl];
cnt[(pl+1)%3]++;
cnt[(pl+2)%3]--;
sz[pl]--;
sz[(pl+1)%3]++;
ans=(ans+x*f((pl+1)%3,cnt,sz)%mod)%mod;
cnt[(pl+1)%3]--;
cnt[(pl+2)%3]++;
sz[pl]++;
sz[(pl+1)%3]--;
}
return ans;
}
void solve(){
for(int i=0;i<3;i++){
for(int j=0;j<2*n;j++){
int x;
cin>>x;
if(m[i][x])m[i].erase(x);
else m[i][x]=1;
}
}
for(int i=0;i<3;i++){
cnt[i]=0;
sz[i]=0;
for(auto x:m[i]){
if(!x.second)continue;
sz[i]++;
if(m[(i+1)%3][x.first])cnt[i]++;
}
//cout<<cnt[i]<<' '<<sz[i]<<endl;
}
memset(dp,-1,sizeof dp);
cout<<f(0,cnt,sz)<<endl;
}
int main()
{
IOS
int t;
cin>>n;
cin>>t;
while(t--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |