Submission #532191

# Submission time Handle Problem Language Result Execution time Memory
532191 2022-03-02T12:18:52 Z i_am_noob Fishing Game (RMI19_fishing) C++17
100 / 100
277 ms 74000 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")

#define ll long long
#define int ll
#define ull unsigned ll
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define chkmin(a,b) (a=min(a,b))
#define chkmax(a,b) (a=max(a,b))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
//#define inf 1010000000
#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 777771449
#endif

const int mod=1000000007;
const int maxn=305,maxm=5,maxk=7777714;

//i_am_noob
int n,t,cnt[3],dp[maxn][maxn][maxn];
bool vis[maxn][maxn][maxn];
vector<vector<int>> vec(maxn);

int solve(int x, int y, int z){
    if(vis[x][y][z]) return dp[x][y][z];
    vis[x][y][z]=1;
    if(x+y+z==0){
        dp[x][y][z]=1;
        return 1;
    }
    dp[x][y][z]=0;
    rep1(mask,7){
        int nx=x,ny=y,nz=z,tot=1;
        bool ok=1;
        if(nx==0&&nz==0){
            if(mask&1) ok=0;
        }
        else if(mask&1){
            tot=tot*nz%mod;
            nz--;
            ny++;
        }
        else{
            tot=tot*nx%mod;
            nx--;
        }
        if(nx==0&&ny==0){
            if(mask>>1&1) ok=0;
        }
        else if(mask>>1&1){
            tot=tot*nx%mod;
            nx--;
            nz++;
        }
        else{
            tot=tot*ny%mod;
            ny--;
        }
        if(ny==0&&nz==0){
            if(mask>>2&1) ok=0;
        }
        else if(mask>>2&1){
            tot=tot*ny%mod;
            ny--;
            nx++;
        }
        else{
            tot=tot*nz%mod;
            nz--;
        }
        if(tot&&ok) dp[x][y][z]+=solve(nx,ny,nz)*tot%mod; 
    }
    dp[x][y][z]%=mod;
    return dp[x][y][z];
}

void orzck(){
    cin >> n >> t;
    while(t--){
        rep(n*3) vec[i].clear();
        rep(3) rep1(j,n*2){
            int x;
            cin >> x;
            x--;
            vec[x].pb(i);
        }
        rep(3) cnt[i]=0;
        rep(n*3) if(vec[i][0]!=vec[i][1]) cnt[vec[i][0]+vec[i][1]-1]++;
        swap(cnt[1],cnt[2]);
        rep(n*3) rep1(j,n*3) memset(vis[i][j],0,sizeof vis[i][j]);
        cout << solve(cnt[0],cnt[1],cnt[2]) << "\n";
    }
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    orzck();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 2 ms 1228 KB Output is correct
4 Correct 3 ms 3532 KB Output is correct
5 Correct 41 ms 19152 KB Output is correct
6 Correct 67 ms 27460 KB Output is correct
7 Correct 132 ms 37248 KB Output is correct
8 Correct 181 ms 48712 KB Output is correct
9 Correct 225 ms 61584 KB Output is correct
10 Correct 277 ms 74000 KB Output is correct