Submission #347446

#TimeUsernameProblemLanguageResultExecution timeMemory
347446ijxjdjdFishing Game (RMI19_fishing)C++14
0 / 100
339 ms333676 KiB
#include <bits/stdc++.h> #define FR(i, N) for (int i = 0; i < int(N); i++) #define all(x) begin(x), end(x) using namespace std; using ll = long long; ll MOD = (int)(1e9) + 7; const int MAXN = 305; int dp[MAXN][MAXN][MAXN][3]; ll fill(int a, int b, int c, int d) { if (a == 0 && b == 0 && c == 0) { return 1; } if (a < 0 || b < 0 || c < 0 || d >= 3) { return 0; } if (dp[a][b][c][d] != -1) { return dp[a][b][c][d]; } else { dp[a][b][c][d] = (int)((a*fill(b, c, a-1, 0) + c*fill(b+1, c-1, a, d+1))%MOD); return dp[a][b][c][d]; } } int main() { cin.tie(0); cin.sync_with_stdio(0); FR(i, MAXN) { FR(j, MAXN) { FR(k, MAXN) { FR(z, 3) { dp[i][j][k][z] = -1; } } } } int T; int N; cin >> N; cin >> T; while (T-->0) { vector<int> vecs[3]; FR(j, 3) { FR(i, 2*N) { int a; cin >> a; auto it = find(all(vecs[j]), a); if (it == vecs[j].end()) { vecs[j].push_back(a); } } } int c[3]; memset(c, 0, sizeof(c)); FR(j, 3) { FR(i, vecs[j].size()) { if (find(all(vecs[(j+1)%3]), vecs[j][i]) != vecs[(j+1)%3].end()) { c[j]++; } } } cout << fill(c[0], c[1], c[2], 0) << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...