Submission #332074

# Submission time Handle Problem Language Result Execution time Memory
332074 2020-12-01T11:02:41 Z alextodoran Fishing Game (RMI19_fishing) C++17
100 / 100
1576 ms 107712 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 102;

const int MOD = 1e9+7;

int n, t;

int dp[3 * N_MAX][3 * N_MAX][3 * N_MAX];

bool a[3 * N_MAX], b[3 * N_MAX], c[3 * N_MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> t;
    dp[0][0][0] = 1;
    for(int s = 1; s <= 6 * n; s++)
        for(int i = 0; i <= 3 * n && i <= s; i++)
            for(int j = max(0, s - 3 * n); j <= 3 * n && i + j <= s; j++)
            {
                int k = s - i - j;
                ll sum = 0;
                int start = 1;
                if(min({i, j, k}) - 2 > 0)
                    start = 2;
                for(int x = start; x <= 3; x++)
                    for(int y = start; y <= 3; y++)
                        for(int z = start; z <= 3; z++)
                        {
                            if(x != 2 && y != 2 && z != 2)
                                continue;
                            int i1 = i, j1 = j, k1 = k;
                            int prod = 1;
                            if(x == 1)
                            {
                                if(i1 + k1 > 0)
                                    continue;
                            }
                            else if(x == 2)
                            {
                                if(i1 == 0)
                                    continue;
                                prod *= i1;
                                i1--;
                            }
                            else
                            {
                                if(k1 == 0)
                                    continue;
                                prod *= k1;
                                j1++;
                                k1--;
                            }
                            if(y == 1)
                            {
                                if(j1 + i1 > 0)
                                    continue;
                            }
                            else if(y == 2)
                            {
                                if(j1 == 0)
                                    continue;
                                prod *= j1;
                                j1--;
                            }
                            else
                            {
                                if(i1 == 0)
                                    continue;
                                prod *= i1;
                                k1++;
                                i1--;
                            }
                            if(z == 1)
                            {
                                if(k1 + j1 > 0)
                                    continue;
                            }
                            else if(z == 2)
                            {
                                if(k1 == 0)
                                    continue;
                                prod *= k1;
                                k1--;
                            }
                            else
                            {
                                if(j1 == 0)
                                    continue;
                                prod *= j1;
                                i1++;
                                j1--;
                            }
                            sum += 1LL * dp[i1][j1][k1] * prod;
                        }
                dp[i][j][k] = sum % MOD;
            }
    while(t--)
    {
        for(int i = 1; i <= n * 3; i++)
            a[i] = b[i] = c[i] = false;
        for(int i = 1; i <= n * 2; i++)
        {
            int card;
            cin >> card;
            a[card] = true;
        }
        for(int i = 1; i <= n * 2; i++)
        {
            int card;
            cin >> card;
            b[card] = true;
        }
        for(int i = 1; i <= n * 2; i++)
        {
            int card;
            cin >> card;
            c[card] = true;
        }
        int I = 0, J = 0, K = 0;
        for(int i = 1; i <= n * 3; i++)
            I += (a[i] && b[i]);
        for(int i = 1; i <= n * 3; i++)
            J += (b[i] && c[i]);
        for(int i = 1; i <= n * 3; i++)
            K += (c[i] && a[i]);
        cout << dp[I][J][K] << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 3 ms 1644 KB Output is correct
4 Correct 10 ms 4972 KB Output is correct
5 Correct 138 ms 28268 KB Output is correct
6 Correct 232 ms 40300 KB Output is correct
7 Correct 519 ms 54508 KB Output is correct
8 Correct 688 ms 70764 KB Output is correct
9 Correct 1229 ms 89396 KB Output is correct
10 Correct 1576 ms 107712 KB Output is correct