Submission #476215

#TimeUsernameProblemLanguageResultExecution timeMemory
476215iulia13Fishing Game (RMI19_fishing)C++14
0 / 100
10 ms1848 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 305; const int mod = 1e9 + 7; int dp[N][N][N]; void adun(int &a, int b) { a += b; if (a >= mod) a -= mod; } int inm(int a, int b) { ll c = 1ll * a * b; c %= mod; return c; } ///dp[i][j][k] = nr moduri daca a,b au i in comun /// b,c au j in comun /// c,a au k in comun /** op 1) a NU are ce sa ii dea lui b => a = 0 => i + k = 0 2) a -> b una pe care o are b => i posibilitati, i-- 3) a -> b una pe care o are c => k posibilitati, j++ k-- tb macar o op 2 ca s sa scada **/ int pos; void op1(int i, int j, int k) { if (i + k != 0) pos = 0; } void op2(int &i, int j, int k) { pos *= i; i--; } void op3(int i, int &j, int &k) { pos *= k; j++; k--; } int vc[3][N]; int x[3][3]; int main() { ///freopen("x.in", "r", stdin); /// freopen("x.out", "w", stdout); int n, t; cin >> n >> t; dp[0][0][0] = 1; for (int s = 1; s <= 6 * n; s++) for (int i = 0; i <= 3 * n && i <= s; i++) for (int j = 0; j <= 3 * n && j + i <= s; i++) { int k = s - i - j; if (i + k > 3 * n || i + j > 3 * n || i + k > 3 * n) continue; for (int ab = 1; ab <= 3; ab++) for (int bc = 1; bc <= 3; bc++) for (int ca = 1; ca <= 3; ca++) { if (ab != 2 && bc != 2 && ca != 2) continue; pos = 1; int I = i, J = j, K = k; if (ab == 1) op1(I, J, K); else if (ab == 2) op2(I, J, K); else op3(I, J, K); if (bc == 1) op1(J, K, I); else if (bc == 2) op2(J, K, I); else op3(J, K, I); if (ca == 1) op1(K, I, J); else if (ca == 2) op2(K, I, J); else op3(K, I, J); if (I < 0 || J < 0 || K < 0) continue; adun(dp[i][j][k], inm(pos, dp[I][J][K])); } } while(t--) { for (int i = 0; i < 3; i++) for (int j = 1; j <= 3 * n; j++) vc[i][j] = 0; for (int i = 0; i < 3; i++) for (int j = 1; j <= 2 * n; j++) { int nr; cin >> nr; vc[i][nr] = 1; } for (int i = 0; i < 3; i++) for (int j = i + 1; j < 3; j++) { x[i][j] = 0; for (int k = 1; k <= 3 * n; k++) if (vc[i][k] && vc[j][k]) x[i][j]++; } cout << dp[x[0][1]][x[1][2]][x[0][2]] << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...