Submission #476215

# Submission time Handle Problem Language Result Execution time Memory
476215 2021-09-25T11:00:58 Z iulia13 Fishing Game (RMI19_fishing) C++14
0 / 100
10 ms 1848 KB
#include <bits/stdc++.h>

using namespace std;
#define ll long long
const int N = 305;
const int mod = 1e9 + 7;
int dp[N][N][N];
void adun(int &a, int b)
{
    a += b;
    if (a >= mod)
        a -= mod;
}
int inm(int a, int b)
{
    ll c = 1ll * a * b;
    c %= mod;
    return c;
}
///dp[i][j][k] = nr moduri daca a,b au i in comun
///                             b,c au j in comun
///                             c,a au k in comun
/**
op
1) a NU are ce sa ii dea lui b => a = 0 => i + k = 0
2) a -> b una pe care o are b => i posibilitati, i--
3) a -> b una pe care o are c => k posibilitati, j++ k--
tb macar o op 2 ca s sa scada
**/
int pos;
void op1(int i, int j, int k)
{
    if (i + k != 0)
        pos = 0;
}
void op2(int &i, int j, int k)
{
    pos *= i;
    i--;
}
void op3(int i, int &j, int &k)
{
    pos *= k;
    j++;
    k--;
}
int vc[3][N];
int x[3][3];
int main()
{
    ///freopen("x.in", "r", stdin);
   /// freopen("x.out", "w", stdout);
    int n, t;
    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 = 0; j <= 3 * n && j + i <= s; i++)
            {
                int k = s - i - j;
                if (i + k > 3 * n || i + j > 3 * n || i + k > 3 * n)
                    continue;
                for (int ab = 1; ab <= 3; ab++)
                    for (int bc = 1; bc <= 3; bc++)
                        for (int ca = 1; ca <= 3; ca++)
                        {
                            if (ab != 2 && bc != 2 && ca != 2)
                                continue;
                            pos = 1;
                            int I = i, J = j, K = k;
                            if (ab == 1)
                                op1(I, J, K);
                            else
                            if (ab == 2)
                                op2(I, J, K);
                            else
                                op3(I, J, K);

                            if (bc == 1)
                                op1(J, K, I);
                            else
                            if (bc == 2)
                                op2(J, K, I);
                            else
                                op3(J, K, I);

                            if (ca == 1)
                                op1(K, I, J);
                            else
                            if (ca == 2)
                                op2(K, I, J);
                            else
                                op3(K, I, J);
                            if (I < 0 || J < 0 || K < 0)
                                continue;
                            adun(dp[i][j][k], inm(pos, dp[I][J][K]));
                        }

            }
    while(t--)
    {
        for (int i = 0; i < 3; i++)
            for (int j = 1; j <= 3 * n; j++)
                vc[i][j] = 0;
        for (int i = 0; i < 3; i++)
            for (int j = 1; j <= 2 * n; j++)
            {
                int nr;
                cin >> nr;
                vc[i][nr] = 1;
            }

        for (int i = 0; i < 3; i++)
            for (int j = i + 1; j < 3; j++)
            {
                x[i][j] = 0;
                for (int k = 1; k <= 3 * n; k++)
                    if (vc[i][k] && vc[j][k])
                        x[i][j]++;
            }
        cout << dp[x[0][1]][x[1][2]][x[0][2]] << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Incorrect 1 ms 588 KB Output isn't correct
5 Incorrect 4 ms 972 KB Output isn't correct
6 Incorrect 4 ms 1228 KB Output isn't correct
7 Incorrect 6 ms 1320 KB Output isn't correct
8 Incorrect 7 ms 1484 KB Output isn't correct
9 Incorrect 9 ms 1740 KB Output isn't correct
10 Incorrect 10 ms 1848 KB Output isn't correct