Submission #198087

#TimeUsernameProblemLanguageResultExecution timeMemory
198087model_codeFishing Game (RMI19_fishing)C++17
100 / 100
1526 ms107180 KiB
/** * user: volkov-d03 * fname: Ivan * lname: Volkov * task: fishing * score: 100.0 * date: 2019-10-11 08:23:34.758620 */ #include <iostream> #include <algorithm> #include <vector> #include <unordered_map> #define int long long using namespace std; const int M = 1e9 + 7, MAX_N = 302; //signed dp[2][3][MAX_N][MAX_N][MAX_N]; unordered_map <signed, signed> dp; long long hashh(int i, int j, int k, int t, int flag) { long long res = flag * 3 * MAX_N * MAX_N * MAX_N; res += t * MAX_N * MAX_N * MAX_N; res += i * MAX_N * MAX_N; res += j * MAX_N; res += k; return res; } int calc(int i, int j, int k, int t, bool flag) { int h = hashh(i, j, k, t, flag); if (i + j + k == 0) { dp[h] = 1; //dp[flag][t][i][j][k] = 1; return 1; } if (t == 0 && !flag) return 0; if (t == 0) flag = 0; if (dp.find(h) != dp.end()) return dp[h]; dp[h] = 0; if (t == 0) { if (j + k == 0) { dp[h] = calc(i, j, k, 1, flag); return dp[h]; } if (j != 0) dp[h] = (j * calc(i + 1, j - 1, k, 1, flag)) % M; if (k != 0) dp[h] = (dp[h] + k * calc(i, j, k - 1, 1, 1)) % M; } if (t == 1) { if (i + k == 0) { dp[h] = calc(i, j, k, 2, flag); return dp[h]; } if (i != 0) dp[h] = (i * calc(i - 1, j, k, 2, 1)) % M; if (k != 0) dp[h] = (dp[h] + k * calc(i, j + 1, k - 1, 2, flag)) % M; } if (t == 2) { if (i + j == 0) { dp[h] = calc(i, j, k, 0, flag); return dp[h]; } if (i != 0) dp[h] = (i * calc(i - 1, j, k + 1, 0, flag)) % M; if (j != 0) dp[h] = (dp[h] + j * calc(i, j - 1, k, 0, 1)) % M; } //cout << i << ' ' << j << ' ' << k << ' ' << t << ' ' << dp[i][j][k][t] << endl; return dp[h]; } vector <int> have[MAX_N]; signed main() { int n, t; cin >> n >> t; for (int tt = 0; tt < t; tt++) { int a = 0, b = 0, c = 0; for (int i = 0; i < 3 * n; i++) have[i].clear(); for (int i = 0; i < 2 * n; i++) { int x; cin >> x; have[x - 1].push_back(0); } for (int i = 0; i < 2 * n; i++) { int x; cin >> x; have[x - 1].push_back(1); } for (int i = 0; i < 2 * n; i++) { int x; cin >> x; have[x - 1].push_back(2); } for (int i = 0; i < 3 * n; i++) { if (have[i][0] == 0 && have[i][1] == 1) c++; if (have[i][0] == 0 && have[i][1] == 2) b++; if (have[i][0] == 1 && have[i][1] == 2) a++; } cout << calc(a, b, c, 0, 1) << "\n"; } //cout << calc(0, 2, 0, 0) << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...