# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
331393 | evpipis | Fishing Game (RMI19_fishing) | C++11 | 146 ms | 107724 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int len = 305, mod = 1e9+7;
int dp[len][len][len];
vector<int> vec[len];
int add(int a, int b){
return (a+b)%mod;
}
int mul(int a, int b){
return (a*1LL*b)%mod;
}
int solve(int x, int y, int z){
if (x == 0 && y == 0 && z == 0)
return 1;
if (dp[x][y][z] != -1)
return dp[x][y][z];
int ans = 0;
for (int bit = 1; bit < 8; bit++){
int s[] = {x, y, z};
int c = 1;
for (int i = 0; i < 3; i++){
if ((bit&(1<<i)) && s[i] > 0)
c = mul(c, s[i]), s[i]--;
else if (!(bit&(1<<i)) && s[(i+2)%3] > 0)
c = mul(c, s[(i+2)%3]), s[(i+2)%3]--, s[(i+1)%3]++;
else
c = 0;
}
if (c > 0)
ans = add(ans, mul(c, solve(s[0], s[1], s[2])));
}
return dp[x][y][z] = ans;
}
int main(){
int n, t;
scanf("%d %d", &n, &t);
for (int x = 0; x <= 3*n; x++)
for (int y = 0; y <= 3*n; y++)
for (int z = 0; z <= 3*n; z++)
dp[x][y][z] = -1;
for (int test = 0; test < t; test++){
for (int card = 1; card <= 3*n; card++)
vec[card].clear();
for (int c = 0; c < 3; c++){
for (int i = 0; i < 2*n; i++){
int card;
scanf("%d", &card);
vec[card].pb(c);
}
}
int x = 0, y = 0, z = 0;
for (int card = 1; card <= 3*n; card++){
int a = vec[card][0], b = vec[card][1];
if (a > b) swap(a, b);
if (a == 0 && b == 1) x++;
if (a == 1 && b == 2) y++;
if (a == 0 && b == 2) z++;
}
printf("%d\n", solve(x, y, z));
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |