# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
854648 | lolismek | Fishing Game (RMI19_fishing) | C++14 | 634 ms | 55804 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 <iostream>
#include <vector>
#define int long long
using namespace std;
const int NMAX = 100;
const int MOD = 1e9 + 7;
int dp[2 * NMAX + 1][2 * NMAX + 1][2 * NMAX + 1];
void op1(int &mult, int &i, int &j, int &k){
if(i + k != 0){
mult = 0;
}
}
void op2(int &mult, int &i, int &j, int &k){
mult *= i;
i--;
}
void op3(int &mult, int &i, int &j, int &k){
mult *= k;
k--;
j++;
}
signed main(){
int n, t;
cin >> n >> t;
dp[0][0][0] = 1;
for(int sum = 1; sum <= 6 * n; sum++){
for(int w1 = 0; w1 <= sum && w1 <= 2 * n; w1++){
for(int w2 = 0; w1 + w2 <= sum && w2 <= 2 * n; w2++){
int w3 = sum - (w1 + w2);
if(w1 + w3 > 3 * n || w2 + w3 > 3 * n || w1 + w2 > 3 * n){
continue;
}
for(int s1 = 1; s1 <= 3; s1++){
for(int s2 = 1; s2 <= 3; s2++){
for(int s3 = 1; s3 <= 3; s3++){
if(s1 != 2 && s2 != 2 && s3 != 2){
continue;
}
int i = w1, j = w2, k = w3, mult = 1;
if(s1 == 1){
op1(mult, i, j, k);
}else if(s1 == 2){
op2(mult, i, j, k);
}else{
op3(mult, i, j, k);
}
if(s2 == 1){
op1(mult, j, k, i);
}else if(s2 == 2){
op2(mult, j, k, i);
}else{
op3(mult, j, k, i);
}
if(s3 == 1){
op1(mult, k, i, j);
}else if(s3 == 2){
op2(mult, k, i, j);
}else{
op3(mult, k, i, j);
}
if(mult == 0 || i < 0 || j < 0 || k < 0){
continue;
}
(dp[w1][w2][w3] += (dp[i][j][k] * mult) % MOD) %= MOD;
}
}
}
}
}
}
while(t--){
vector <bool> a(3 * n, 0);
vector <bool> b(3 * n, 0);
vector <bool> c(3 * n, 0);
for(int i = 1; i <= 2 * n; i++){
int x;
cin >> x;
a[x] = 1;
}
for(int i = 1; i <= 2 * n; i++){
int x;
cin >> x;
b[x] = 1;
}
for(int i = 1; i <= 2 * n; i++){
int x;
cin >> x;
c[x] = 1;
}
int w1 = 0, w2 = 0, w3 = 0;
for(int i = 1; i <= 3 * n; i++){
w1 += (a[i] && b[i]);
w2 += (b[i] && c[i]);
w3 += (c[i] && a[i]);
}
cout << dp[w1][w2][w3] << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |