# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
375045 | 2021-03-09T00:42:45 Z | iliccmarko | Fishing Game (RMI19_fishing) | C++14 | 371 ms | 215148 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define INF 1000000000 #define LINF 1000000000000000LL #define pb push_back #define all(x) x.begin(), x.end() #define len(s) (int)s.size() #define test_case { int t; cin>>t; while(t--)solve(); } #define single_case solve(); #define line cerr<<"----------"<<endl; #define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); } #define mod 1000000007LL const int N = 305; ll dp[N][N][N]; ll a[N], b[N], c[N]; ll resi(ll x, ll y, ll z) { //cout<<x<<" "<<y<<" "<<z<<endl; if(x==0&&y==0&&z==0) return 1; if(dp[x][y][z]!=-1) return dp[x][y][z]; dp[x][y][z] = 0; for(int bit = 1;bit<8;bit++) { int s[] = {x, y, z}; ll c = 1; for(int i = 0;i<3;i++) { if(bit&(1<<i)&&s[i]) s[i]--, c = (c*(s[i]+1))%mod; else if(!(bit&(1<<i))&&s[(i+2)%3]>0) c = (c*(s[(i+2)%3]))%mod, s[(i+2)%3]--, s[(i+1)%3]++; else if(!(bit&(1<<i))&&s[i]==0&&s[(i+2)%3]==0) continue; else c = 0; } dp[x][y][z] = (dp[x][y][z]+c*resi(s[0], s[1], s[2]))%mod; } return dp[x][y][z]; } int main() { ios ll n, t; cin>>n>>t; for(int i = 0;i<3*n+2;i++)for(int j = 0;j<3*n+2;j++)for(int z = 0;z<3*n+2;z++) dp[i][j][z] = -1; dp[0][0][0] = 1; while(t--) { //for(int i = 0;i<3*n+2;i++)for(int j = 0;j<3*n+2;j++)for(int z = 0;z<3*n+2;z++) dp[i][j][z] = -1; for(int i = 0;i<N;i++) a[i] = b[i] = c[i] = 0; for(int i = 0;i<2*n;i++) { ll x; cin>>x; a[x]++; } for(int i = 0;i<2*n;i++) { ll x; cin>>x; b[x]++; } for(int i = 0;i<2*n;i++) { ll x; cin>>x; c[x]++; } ll x, y, z; x = y = z = 0; for(int i = 1;i<=3*n;i++) if(a[i]&&b[i]) x++; for(int i = 1;i<=3*n;i++) if(b[i]&&c[i]) y++; for(int i = 1;i<=3*n;i++) if(a[i]&&c[i]) z++; cout<<resi(x, y, z)<<endl; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 1 ms | 620 KB | Output is correct |
3 | Correct | 2 ms | 2924 KB | Output is correct |
4 | Correct | 8 ms | 9708 KB | Output is correct |
5 | Correct | 61 ms | 56064 KB | Output is correct |
6 | Correct | 99 ms | 80108 KB | Output is correct |
7 | Correct | 143 ms | 108524 KB | Output is correct |
8 | Correct | 200 ms | 141164 KB | Output is correct |
9 | Correct | 274 ms | 178200 KB | Output is correct |
10 | Correct | 371 ms | 215148 KB | Output is correct |