Submission #274506

#TimeUsernameProblemLanguageResultExecution timeMemory
274506theStaticMindFishing Game (RMI19_fishing)C++14
100 / 100
668 ms107256 KiB
#include<bits/stdc++.h> #define pb push_back #define ii pair<int,int> #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define INF 100000000000000000 #define modulo 1000000007 #define mod 998244353 //#define int long long int using namespace std; int dp[301][301][301]; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, q; cin >> n >> q; while(q--){ map<int, int> A; map<int, int> B; map<int, int> C; for(int i = 0; i < n*2; i++){ int x; cin >> x; A[x]++; } for(int i = 0; i < n*2; i++){ int x; cin >> x; B[x]++; } for(int i = 0; i < n*2; i++){ int x; cin >> x; C[x]++; } for(int i = 0; i <= 300; i++){ for(int j = 0; j <= 300; j++){ for(int k = 0; k <= 300; k++){ dp[i][j][k] = 0; } } } int a = 0, b = 0, c = 0; for(int i = 1; i <= 3*n; i++){ if(A[i] == 1 && B[i] == 1) a++; if(A[i] == 1 && C[i] == 1) b++; if(B[i] == 1 && C[i] == 1) c++; } dp[a][b][c] = 1; auto go = [&](int i, int j, int k, int o, int p, int r){ int x = i, y = j, z = k; int K = 1; if(o == -1){ if(x != 0 || y != 0) return; } else if(o == 0){ if(x){ K *= x; x--; } else return; } else{ if(y){ K *= y; y--; z++; } else return; } if(p == -1){ if(x != 0 || z != 0) return; } else if(p == 0){ if(x){ K *= x; x--; y++; } else return; } else{ if(z){ K *= z; z--; } else return; } if(r == -1){ if(y != 0 || z != 0) return; } else if(r == 0){ if(y){ K *= y; y--; } else return; } else{ if(z){ K *= z; z--; x++; } else return; } if(x >= 0 && y >= 0 && z >= 0 && !(x == i && y == j && z == k)){ dp[x][y][z] = (dp[x][y][z] + 1ll * K * dp[i][j][k] % modulo) % modulo; } }; for(int s = a + b + c; s >= 0; s--){ for(int i = 0; i <= 300; i++){ for(int j = 0; j <= 300 && i + j <= s; j++){ int k = s - i - j; if(dp[i][j][k]) for(int o = -1; o <= 1; o++){ for(int p = -1; p <= 1; p++){ for(int r = -1; r <= 1; r++){ go(i, j, k, o, p, r); } } } } } } cout << dp[0][0][0] << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...