Submission #274082

#TimeUsernameProblemLanguageResultExecution timeMemory
274082FashoFishing Game (RMI19_fishing)C++14
100 / 100
427 ms164032 KiB
#include <bits/stdc++.h> #define N 301 #define ll long long int #define fo(i,x,y) for(int i=x;i<=y;i++) #define fs(ar,n) fo(i,1,n) cin>>ar[i] #define sp " " #define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false) #define pb push_back #define ppb pop_back #define fi first #define se second #define ii pair<int,int> #define lli pair<ll,ll> #define mod 1000000007 using namespace std; ll n,m,sum,t,tut1[N],tut2[N],dp[201][201][201][3][2]; ll add(ll x,ll y) { x%=mod; y%=mod; return (((x+y)%mod)+mod)%mod; } ll carp(ll x,ll y) { x%=mod; y%=mod; return (((x*y)%mod)+mod)%mod; } ll f(ll a,ll b,ll c,ll x,bool flag) { if(dp[a][b][c][x][flag]) return dp[a][b][c][x][flag]; if(!a && !b && !c) return dp[a][b][c][x][flag]=1; // cerr<<a<<sp<<b<<sp<<c<<sp<<x<<endl; if(x==0) { ll top=0; if(!a && !b) return dp[a][b][c][x][flag]=f(a,b,c,1,flag); if(a) top=add(top,carp(f(a-1,b,c,1,1),a)); if(b) top=add(top,carp(f(a,b-1,c+1,1,flag),b)); return dp[a][b][c][x][flag]=top; } if(x==1) { ll top=0; if(!a && !c) return dp[a][b][c][x][flag]=f(a,b,c,2,flag); if(c) top=add(top,carp(f(a,b,c-1,2,1),c)); if(a) top=add(top,carp(f(a-1,b+1,c,2,flag),a)); // cout<<a<<sp<<b<<sp<<c<<sp<<top<<endl; return dp[a][b][c][x][flag]=top; } if(x==2) { ll top=0; if(!b && !c) return dp[a][b][c][x][flag]=f(a,b,c,0,0); if(b) top=add(top,carp(f(a,b-1,c,0,0),b)); if(c && flag) top=add(top,carp(f(a+1,b,c-1,0,0),c)); return dp[a][b][c][x][flag]=top; } return 1; } int main() { fast; cin>>n>>t; while(t--) { ll a=0,b=0,c=0; fo(i,1,n*3) tut1[i]=0,tut2[i]=0; fo(i,1,3) fo(j,1,n*2) { ll x; cin>>x; // cout<<x<<endl; if(tut1[x]) { tut2[x]=i; if(tut1[x]==i) continue; if(tut1[x]==1) { if(i==2) a++; else b++; } else c++; } else tut1[x]=i; } // cout<<a<<sp<<b<<sp<<c<<endl; cout<<f(a,b,c,0,0)<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...