| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 331396 | evpipis | Fishing Game (RMI19_fishing) | C++11 | 108 ms | 33644 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 = 105, mod = 1e9+7;
int dp[2*len][2*len][2*len];
vector<int> vec[3*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 < (1<<3); 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 if (!(bit&(1<<i)) && s[(i+2)%3] == 0 && s[i] == 0)
                continue;
            else
                c = 0;
        }
        if (c > 0)
            ans = add(ans, mul(c, solve(s[0], s[1], s[2])));
    }
    //printf("solve(%d, %d, %d) = %d\n", x, y, z, ans);
    return dp[x][y][z] = ans;
}
int main(){
    int n, t;
    scanf("%d %d", &n, &t);
    for (int x = 0; x <= 2*n; x++)
        for (int y = 0; y <= 2*n; y++)
            for (int z = 0; z <= 2*n; z++)
                dp[x][y][z] = -1;
    /*for (int x = 0; x <= 2*n; x++)
        for (int y = 0; y <= 2*n; y++)
            for (int z = 0; z <= 2*n; z++)
                if (x+y+z <= 6*n)
                    solve(x, y, z);*/
    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("x = %d, y = %d, z = %d\n", x, y, z);
        printf("%d\n", solve(x, y, z));
    }
    return 0;
}
/*
1 1
1 1
2 3
2 3
*/
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
