답안 #477906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477906 2021-10-04T15:07:02 Z Alexandruabcde Fishing Game (RMI19_fishing) C++14
70 / 100
2000 ms 48244 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

LL MOD = 1000000007;
constexpr int NMAX = 305;

int dp[NMAX][NMAX][NMAX];

void Do (int what, int &i, int &j, int &k, int &coef) {
    if (what == 1) {
        if (i + k != 0)
            coef = 0;

        return;
    }

    if (what == 2) {
        coef *= i;
        -- i;

        return;
    }

    if (what == 3) {
        coef *= k;
        ++ j;
        -- k;
    }
}

bool Check (int i, int j, int k, int coef) {
    return (i >= 0 && j >= 0 && k >= 0 && coef > 0);
}

void Precalculare (int N) {
    dp[0][0][0] = 1;

    for (int Total = 1; Total <= 6 * N; ++ Total )
        for (int comun_ab = 0; comun_ab <= 2*N && comun_ab <= Total; ++ comun_ab)
            for (int comun_bc = 0; comun_bc <= 2*N && comun_bc <= Total; ++ comun_bc) {
                int comun_ac = Total - comun_ab - comun_bc;

                if (comun_ab + comun_bc > 3 * N && comun_ab + comun_ac > 3 * N && comun_bc + comun_ac > 3 * N)
                    continue;

                for (int op_1 = 1; op_1 <= 3; ++ op_1)
                    for (int op_2 = 1; op_2 <= 3; ++ op_2)
                        for (int op_3 = 1; op_3 <= 3; ++ op_3) {
                            int i = comun_ab, j = comun_bc, k = comun_ac;

                            if (op_1 != 2 && op_2 != 2 && op_3 != 2)
                                continue;

                            int coef = 1;

                            Do(op_1, i, j, k, coef);
                            if (!Check(i, j, k, coef)) continue;
                            Do(op_2, j, k, i, coef);
                            if (!Check(i, j, k, coef)) continue;
                            Do(op_3, k, i, j, coef);
                            if (!Check(i, j, k, coef)) continue;

                            dp[comun_ab][comun_bc][comun_ac] = (dp[comun_ab][comun_bc][comun_ac] + 1LL * coef * dp[i][j][k]) % MOD;
                        }
            }
}

int N;

int fr[3][NMAX];

void Read () {
    for (int i = 0; i < 3; ++ i ) {
        for (int j = 1; j <= 2*N; ++ j ) {
            int x;
            cin >> x;

            fr[i][x]++;
        }
    }
}

void Solve () {
    int good[3];
    good[0] = good[1] = good[2] = 0;
    for (int i = 1; i <= 3*N; ++ i ) {
        if (fr[0][i] && fr[1][i]) good[0]++;
        if (fr[1][i] && fr[2][i]) good[1]++;
        if (fr[2][i] && fr[0][i]) good[2]++;

        fr[0][i] = fr[1][i] = fr[2][i] = 0;
    }

    cout << dp[good[0]][good[1]][good[2]] << '\n';
}

void do_Testcase() {
    Read();

    Solve();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    cin >> N >> T;

    Precalculare(N);

    for (; T; -- T ) {
        do_Testcase();
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 4 ms 848 KB Output is correct
4 Correct 26 ms 2484 KB Output is correct
5 Correct 389 ms 12880 KB Output is correct
6 Correct 704 ms 18388 KB Output is correct
7 Correct 1114 ms 24684 KB Output is correct
8 Incorrect 1646 ms 31852 KB Output isn't correct
9 Execution timed out 2062 ms 40340 KB Time limit exceeded
10 Execution timed out 2091 ms 48244 KB Time limit exceeded