답안 #854623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854623 2023-09-28T08:34:14 Z Tenis0206 Fishing Game (RMI19_fishing) C++11
0 / 100
2000 ms 37028 KB
#include <bits/stdc++.h>

using namespace std;

const int nmax = 100;
const int Mod = 1e9 + 7;

int n;

int dp[3 * nmax + 5][3 * nmax + 5][3 * nmax + 5];

pair<int,int> p[3 * nmax + 5];

void update(int ab, int ac, int bc, int a, int b, int c)
{
    if(ab==0 && ac==2 && bc==0)
    {
        ab = 0;
    }
    int last_nr = ab + ac + bc;
    int last_ab = ab;
    int last_ac = ac;
    if(a==2)
    {
        /// a da una comuna intre b si c
        return;
    }
    if(b==3)
    {
        /// b da una comuna intre c si a
        return;
    }
    if(c==1)
    {
        ///
        return;
    }

    int coef = 1;

    if(ab + ac == 0)
    {
        if(a!=1)
        {
            return;
        }
    }
    else
    {
        if(a==1)
        {
            coef = 1LL * coef * ab % Mod;
            --ab;
        }
        else if(a==3)
        {
            coef = 1LL * coef * ac % Mod;
            --ac;
            ++bc;
        }
    }

    if(ab < 0 || ac < 0 || bc < 0)
    {
        return;
    }
    if(bc + ab == 0)
    {
        if(b!=1)
        {
            return;
        }
    }
    else
    {
        if(b==1)
        {
            coef = 1LL * coef * ab % Mod;
            --ab;
            ++ac;
        }
        else if(b==2)
        {
            coef = 1LL * coef * bc % Mod;
            --bc;
        }
    }

    if(ab < 0 || ac < 0 || bc < 0)
    {
        return;
    }
    if(ac + bc == 0)
    {
        if(c!=2)
        {
            return;
        }
    }
    else
    {
        if(c==2)
        {
            coef = 1LL * coef * bc % Mod;
            --bc;
            ++ab;
        }
        else if(c==3)
        {
            coef = 1LL * coef * ac % Mod;
            --ac;
        }
    }

    if(ab + ac + bc == last_nr)
    {
        return;
    }

    if(ab < 0 || ac < 0 || bc < 0)
    {
        return;
    }

    dp[ab + ac + bc][ab][ac] += 1LL * dp[last_nr][last_ab][last_ac] * coef % Mod;
    dp[ab + ac + bc][ab][ac] %= Mod;
}

void solve_test()
{
    for(int i=1; i<=2*n; i++)
    {
        int x;
        cin>>x;
        if(!p[x].first)
        {
            p[x].first = 1;
        }
        else
        {
            p[x].second = 1;
        }
    }
    for(int i=1; i<=2*n; i++)
    {
        int x;
        cin>>x;
        if(!p[x].first)
        {
            p[x].first = 2;
        }
        else
        {
            p[x].second = 2;
        }
    }
    for(int i=1; i<=2*n; i++)
    {
        int x;
        cin>>x;
        if(!p[x].first)
        {
            p[x].first = 3;
        }
        else
        {
            p[x].second = 3;
        }
    }
    int nr_tot = 3 * n;
    int nrab = 0, nrac = 0;
    for(int i=1; i<=3*n; i++)
    {
        if(p[i].first==p[i].second)
        {
            --nr_tot;
            continue;
        }
        if(p[i].first==1 && p[i].second==2)
        {
            ++nrab;
        }
        else if(p[i].first==1 && p[i].second==3)
        {
            ++nrac;
        }
    }
    dp[nr_tot][nrab][nrac] = 1;
    for(int nr=nr_tot; nr>=1; nr--)
    {
        for(int ab=0; ab<=nr; ab++)
        {
            for(int ac=0; ab+ac<=nr; ac++)
            {
                int bc = nr - ab - ac;
                for(int a=1; a<=3; a++)
                {
                    for(int b=1; b<=3; b++)
                    {
                        for(int c=1; c<=3; c++)
                        {
                            update(ab,ac,bc,a,b,c);
                        }
                    }
                }
            }
        }
    }
    cout<<dp[0][0][0]<<'\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifdef home
    freopen("nr.in","r",stdin);
    freopen("nr.out","w",stdout);
#endif // home
    int t;
    cin>>n>>t;
    for(int i=1; i<=t; i++)
    {
        solve_test();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Incorrect 1 ms 2392 KB Output isn't correct
3 Incorrect 3 ms 2652 KB Output isn't correct
4 Incorrect 13 ms 5756 KB Output isn't correct
5 Incorrect 348 ms 13732 KB Output isn't correct
6 Incorrect 641 ms 17236 KB Output isn't correct
7 Incorrect 999 ms 21328 KB Output isn't correct
8 Incorrect 1537 ms 29192 KB Output isn't correct
9 Execution timed out 2060 ms 32796 KB Time limit exceeded
10 Execution timed out 2058 ms 37028 KB Time limit exceeded