Submission #287173

#TimeUsernameProblemLanguageResultExecution timeMemory
287173eohomegrownappsFishing Game (RMI19_fishing)C++14
100 / 100
123 ms63352 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll m = 1e9+7; ll dpv[201][201][201]; //ab, ac, bc ll dp(int ab, int ac, int bc, int curplayer, bool discard){ //cout<<ab<<' '<<ac<<' '<<bc<<' '<<curplayer<<' '<<discard<<'\n'; if (curplayer==0){ if (ab==0&&ac==0&&bc==0){ return 1; } if (discard==false){ return 0; } if (dpv[ab][ac][bc]!=-1){ return dpv[ab][ac][bc]; } discard = false; } ll ans = 0; if (curplayer==0){ if (ab==0 && ac==0){ return dpv[ab][ac][bc]=dp(ab,ac,bc,1,discard); } if (ab>0){ ans+=(ab*dp(ab-1,ac,bc,1,true)); ans%=m; } if (ac>0){ ans+=(ac*dp(ab,ac-1,bc+1,1,discard)); ans%=m; } return dpv[ab][ac][bc]=ans; } else if (curplayer==1){ if (ab==0 && bc==0){ return dp(ab,ac,bc,2,discard); } if (bc>0){ ans+=(bc*dp(ab,ac,bc-1,2,true)); ans%=m; } if (ab>0){ ans+=(ab*dp(ab-1,ac+1,bc,2,discard)); ans%=m; } return ans; } else if (curplayer==2){ if (ac==0 && bc==0){ return dp(ab,ac,bc,0,discard); } if (ac>0){ ans+=(ac*dp(ab,ac-1,bc,0,true)); ans%=m; } if (bc>0){ ans+=(bc*dp(ab+1,ac,bc-1,0,discard)); ans%=m; } return ans; } else { assert(1==0); } } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); int n,t; cin>>n>>t; for (int x = 0; x<=2*n; x++){ for (int y = 0; y<=2*n; y++){ for (int z = 0; z<=2*n; z++){ dpv[x][y][z]=-1; } } } dpv[0][0][0]=1; for (int i = 0; i<t; i++){ vector<vector<int>> cardowners(3*n); for (int p = 0; p<3; p++){ for (int x = 0; x<2*n; x++){ //player a's hand int c; cin>>c; c--; cardowners[c].push_back(p); } } ll ab = 0; ll bc = 0; ll ac = 0; for (int i = 0; i<3*n; i++){ if (cardowners[i][0]==0&&cardowners[i][1]==1){ ab++; } if (cardowners[i][0]==0&&cardowners[i][1]==2){ ac++; } if (cardowners[i][0]==1&&cardowners[i][1]==2){ bc++; } } cout<<dp(ab,ac,bc,0,true)<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...