Submission #259564

# Submission time Handle Problem Language Result Execution time Memory
259564 2020-08-08T02:38:23 Z lyc Fishing Game (RMI19_fishing) C++14
0 / 100
276 ms 524292 KB
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
using ll=long long;

const int mxN = 305;
const int mod = 1e9+7;

int N, T, A[mxN], B[mxN], C[mxN];

int fac[mxN], AB, BC, AC;
int res[mxN][mxN][mxN][3][2];

int dp(int ab, int bc, int ac, int p, int f) {
	if (ab == 0 && bc == 0) return fac[ac];
	if (ab == 0 && ac == 0) return fac[bc];
	if (bc == 0 && ac == 0) return fac[ab];
	int& ans = res[ab][bc][ac][p][f];
	if (~ans) return ans;
	
	ans = 0;
	if (p == 0) {
		if (ab) ans += (ll) ab * dp(ab-1, bc, ac, p+1, 1) % mod;
		if (ac) ans += (ll) ac * dp(ab, bc+1, ac-1, p+1, f) % mod;
		else ans += (ll) dp(ab, bc, ac, p+1, f) % mod;
		ans %= mod;
	} else if (p == 1) {
		if (bc) ans += (ll) bc * dp(ab, bc-1, ac, p+1, 1) % mod;
		if (ab) ans += (ll) ab * dp(ab-1, bc, ac+1, p+1, f) % mod;
		else ans += (ll) dp(ab, bc, ac, p+1, f) % mod;
		ans %= mod;
	} else if (p == 2) {
		if (ac) ans += (ll) ac * dp(ab, bc, ac-1, 0, 0) % mod;
		if (f) {
			if (bc) ans += (ll) bc * dp(ab+1, bc-1, ac, 0, 0) % mod;
			else ans += (ll) dp(ab, bc, ac, 0, 0) % mod;
			ans %= mod;
		}
	}
	return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> N >> T;
    
    fac[0] = 1;
    FOR(i,1,3*N) fac[i] = (ll) fac[i-1] * i % mod;
    memset(res,-1,sizeof res);
    
    //~ TRACE(fac[2]);
    while (T--) {
		FOR(i,1,2*N){ cin >> A[i]; }
		FOR(i,1,2*N){ cin >> B[i]; }
		FOR(i,1,2*N){ cin >> C[i]; }
		
		AB = BC = AC = 0;
		FOR(i,1,2*N) FOR(j,1,2*N) if (A[i] == B[j]) ++AB;
		FOR(i,1,2*N) FOR(j,1,2*N) if (B[i] == C[j]) ++BC;
		FOR(i,1,2*N) FOR(j,1,2*N) if (A[i] == C[j]) ++AC;
		
		//~ TRACE(AB _ BC _ AC);
		cout << dp(AB,BC,AC,0,0) << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Runtime error 258 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 246 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 256 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 260 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 255 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 256 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 259 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 276 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 254 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 259 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)