Submission #443995

#TimeUsernameProblemLanguageResultExecution timeMemory
443995JovanBFishing Game (RMI19_fishing)C++17
100 / 100
170 ms96888 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int MOD = 1000000007; int add(int a, int b){ a += b; if(a >= MOD) a -= MOD; return a; } int mul(int a, int b){ return (1LL*a*b)%MOD; } vector <int> pos[605]; const int G = 205; int hsh(int a, int b, int c, int turn, int dis){ return G*G*G*a + G*G*b + G*c + 10*turn + dis; } int dp[205][205][205][3][2]; int resi(int a, int b, int c, int turn, int dis){ /// a = 1 i 2 /// b = 2 i 3 /// c = 3 i 1 if(a == 0 && b == 0 && c == 0) return 1; int k = dp[a][b][c][turn][dis]; if(k) return k-1; if(turn == 0){ if(a > 0) k = add(k, mul(a, resi(a-1, b, c, 1, 1))); if(c > 0) k = add(k, mul(c, resi(a, b+1, c-1, 1, dis))); if(a == 0 && c == 0) k = add(k, resi(a, b, c, 1, dis)); } else if(turn == 1){ if(b > 0) k = add(k, mul(b, resi(a, b-1, c, 2, 1))); if(a > 0) k = add(k, mul(a, resi(a-1, b, c+1, 2, dis))); if(a == 0 && b == 0) k = add(k, resi(a, b, c, 2, dis)); } else{ if(c > 0) k = add(k, mul(c, resi(a, b, c-1, 0, 0))); if(dis && b > 0) k = add(k, mul(b, resi(a+1, b-1, c, 0, 0))); if(c == 0 && b == 0 && dis) k = add(k, resi(a, b, c, 0, 0)); } dp[a][b][c][turn][dis] = k+1; return k; } void solve(int n){ for(int i=1; i<=3*n; i++) pos[i].clear(); for(int i=1; i<=2*n; i++){ int x; cin >> x; pos[x].push_back(1); } for(int i=1; i<=2*n; i++){ int x; cin >> x; pos[x].push_back(2); } for(int i=1; i<=2*n; i++){ int x; cin >> x; pos[x].push_back(3); } int ima1 = 0, ima2 = 0, ima3 = 0; for(int i=1; i<=3*n; i++){ if(pos[i].size() >= 2 && pos[i][0] != pos[i][1]){ if(pos[i][0] == 1){ if(pos[i][1] == 2) ima1++; else ima3++; } else ima2++; } } cout << resi(ima1, ima2, ima3, 0, 0) << "\n"; } int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n, t; cin >> n >> t; while(t--) solve(n); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...