Submission #568509

# Submission time Handle Problem Language Result Execution time Memory
568509 2022-05-25T15:54:26 Z urosk Fishing Game (RMI19_fishing) C++14
0 / 100
266 ms 147480 KB
// __builtin_popcount(x)
// __builtin_popcountll(x)
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;

#define maxn 105
#define mod 1000000007
ll n;
ll a[3*maxn];
ll b[3*maxn];
ll c[3*maxn];
ll dp[maxn][maxn][maxn][4][2];
ll fact[3*maxn];
ll add(ll x,ll y){
    x+=y;
    if(x<0){
        x%=mod;
        x+=mod;
    }else{
        if(x>=mod) x%=mod;
    }
    return x;
}
ll mul(ll a,ll b){
	ll ans = (a*b)%mod;
	if(ans<0) ans+=mod;
	return ans;
}
ll reshi(ll ab,ll bc,ll ca,ll muv,bool bio){
    if(ab+bc==0||bc+ca==0||ca+ab==0) return fact[max({ab,bc,ca})];
    if(dp[ab][bc][ca][muv][bio]!=-1) return dp[ab][bc][ca][muv][bio];
    ll ans = 0;
    if(muv==1){
        if(ab) ans = add(ans,mul(ab,reshi(ab-1,bc,ca,2,1)));
        if(ca) ans = add(ans,mul(ca,reshi(ab,bc+1,ca-1,2,bio)));
    }else if(muv==2){
        if(bc) ans = add(ans,mul(bc,reshi(ab,bc-1,ca,3,1)));
        if(ab) ans = add(ans,mul(ca,reshi(ab-1,bc,ca+1,3,bio)));
    }else{
        if(ca) ans = add(ans,mul(ca,reshi(ab,bc,ca-1,1,0)));
        if(bio){
            if(bc) ans = add(ans,mul(bc,reshi(ab+1,bc-1,ca,1,0)));
        }
    }
    return dp[ab][bc][ca][muv][bio] = ans;
}
void tc(){
    for(ll i = 0;i<maxn;i++) for(ll j = 0;j<maxn;j++) for(ll k = 0;k<maxn;k++) for(ll e = 0;e<4;e++) for(ll r = 0;r<2;r++) dp[i][j][k][e][r] = -1;
	for(ll i = 1;i<=2*n;i++){
		ll x; cin >> x;
		a[x]++;
		if(a[x]==2) a[x] = 0;
	}
	for(ll i = 1;i<=2*n;i++){
		ll x; cin >> x;
		b[x]++;
		if(b[x]==2) b[x] = 0;
	}
	for(ll i = 1;i<=2*n;i++){
		ll x; cin >> x;
		c[x]++;
		if(c[x]==2) c[x] = 0;
	}
	ll ab = 0,bc = 0,ca = 0;
	for(ll i = 1;i<=3*n;i++){
		if(a[i]&&b[i]) ab++;
		if(c[i]&&b[i]) bc++;
		if(a[i]&&c[i]) ca++;
	}
	cout<<reshi(ab,bc,ca,1,0)<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
	fact[0] = 1;
	for(ll i = 1;i<3*maxn;i++) fact[i] = mul(fact[i-1],i);
	int t; cin >> n >> t;
	while(t--) tc();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 72780 KB Output isn't correct
2 Incorrect 63 ms 72804 KB Output isn't correct
3 Incorrect 63 ms 72788 KB Output isn't correct
4 Incorrect 65 ms 72836 KB Output isn't correct
5 Incorrect 174 ms 72828 KB Output isn't correct
6 Incorrect 217 ms 72780 KB Output isn't correct
7 Incorrect 266 ms 72828 KB Output isn't correct
8 Runtime error 156 ms 147448 KB Execution killed with signal 11
9 Runtime error 115 ms 147456 KB Execution killed with signal 11
10 Runtime error 117 ms 147480 KB Execution killed with signal 11