# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
259538 | tqbfjotld | Fishing Game (RMI19_fishing) | C++14 | 328 ms | 405112 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long memo[205][205][205][3][2];
const long long MOD = 1000000007LL;
long long func(int p12,int p13,int p23,int cur,bool disc){
if (p12==0 && p13==0&&p23==0) return 1;
if (memo[p12][p13][p23][cur][disc]!=-1) return memo[p12][p13][p23][cur][disc];
if (cur==0){
long long ans = 0;
if (p12>0){
ans += p12*func(p12-1,p13,p23,1,false);
}
ans %= MOD;
if (p13>0){
ans += p13*func(p12,p13-1,p23+1,1,disc);
}
ans %= MOD;
if (p12==0 && p13==0){
ans = func(p12,p13,p23,1,disc);
}
return memo[p12][p13][p23][cur][disc] = ans;
}
if (cur==1){
long long ans = 0;
if (p12>0){
ans += p12*func(p12-1,p13+1,p23,2,disc);
}
ans %= MOD;
if (p23>0){
ans += p23*func(p12,p13,p23-1,2,false);
}
ans %= MOD;
if (p12==0&&p23==0){
ans = func(p12,p13,p23,2,disc);
}
return memo[p12][p13][p23][cur][disc] = ans;
}
if (cur==2){
if (disc){
long long ans = 0;
if (p13>0){
ans += p13*func(p12,p13-1,p23,0,true);
}
ans %= MOD;
return memo[p12][p13][p23][cur][disc] = ans;
}
else{
long long ans = 0;
if (p13>0){
ans += p13*func(p12,p13-1,p23,0,true);
}
ans %= MOD;
if (p23>0){
ans += p23*func(p12+1,p13,p23-1,0,true);
}
ans %= MOD;
if (p13==0 && p23==0){
ans = func(p12,p13,p23,0,true);
}
return memo[p12][p13][p23][cur][disc] = ans;
}
}
}
int match[305];
int main(){
//printf("%d\n",sizeof(memo));
memset(memo,-1,sizeof(memo));
int n,T;
scanf("%d%d",&n,&T);
while (T--){
memset(match,-1,sizeof(match));
int c12=0,c13=0,c23=0;
for (int x = 0; x<2*n; x++){
int t;
scanf("%d",&t);match[t] = 0;
}
for (int x = 0; x<2*n; x++){
int t;
scanf("%d",&t);
if (match[t]==0){
c12++;
}
match[t] = 1;
}
for (int x = 0; x<2*n; x++){
int t;
scanf("%d",&t);
if (match[t]==0){
c13++;
}
else if (match[t]==1){
c23++;
}
match[t] = 2;
}
//printf("nums %d %d %d\n",c12,c13,c23);
printf("%lld\n",func(c12,c13,c23,0,true));
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |