Submission #853739

#TimeUsernameProblemLanguageResultExecution timeMemory
853739heeheeheehaawFishing Game (RMI19_fishing)C++17
0 / 100
381 ms218084 KiB
#include <iostream> #define int long long using namespace std; int v[4][305]; int dp[305][305][305]; const int MOD = 1e9 + 7; signed main() { int n, t; cin>>n>>t; while(t--) { for(int i = 0; i <= 3*n; i++) for(int j = 0; j <= 3*n; j++) for(int k = 0; k <= 3*n; k++) dp[i][j][k] = 0; for(int i = 1; i <= 3; i++) for(int j = 1; j <= 2*n; j++) cin>>v[i][j]; int p12 = 0, p23 = 0, p31 = 0; for(int i = 1; i <= 2*n; i++) for(int j = 1; j <= 2*n; j++) if(v[1][i] == v[2][j]) p12++; for(int i = 1; i <= 2*n; i++) for(int j = 1; j <= 2*n; j++) if(v[2][i] == v[3][j]) p23++; for(int i = 1; i <= 2*n; i++) for(int j = 1; j <= 2*n; j++) if(v[3][i] == v[1][j]) p31++; dp[p12][p23][p31] = 1; for(int tot = p12 + p23 + p31; tot > 0; tot--) { for(int c12=0; c12<=tot; c12++) { for(int c23=0; c23+c12<=tot; c23++) { int c31=tot-c12-c23; if(dp[c12][c23][c31] == 0) continue; for(int a = 1; a <= 2; a++) { for(int b = 1; b <= 2; b++) { for(int c = 1; c <= 2; c++) { int ct12 = c12, ct23 = c23, ct31 = c31, prod = 1; if(ct12 > 0 || ct31 > 0) { if(a == 1) prod *= ct31, ct23++, ct31--, prod %= MOD; else prod *= ct12, ct12--, prod %= MOD; } if(ct23 > 0 || ct12 > 0) { if(b == 1) prod *= ct12, ct31++, ct12--, prod %= MOD; else prod *= ct23, ct23--, prod %= MOD; } if(ct31 > 0 || ct23 > 0) { if(c == 1) prod *= ct23, ct12++, ct23--, prod %= MOD; else prod *= ct31, ct31--, prod %= MOD; } if(ct12 >= 0 && ct23 >= 0 && ct31 >= 0 && ct12 + ct23 + ct31 < tot) dp[ct12][ct23][ct31] += dp[c12][c23][c31] * prod % MOD, dp[ct12][ct23][ct31] %= MOD; } } } } } } cout<<dp[0][0][0]<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...