답안 #259527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259527 2020-08-08T01:29:15 Z tqbfjotld Fishing Game (RMI19_fishing) C++14
0 / 100
272 ms 524292 KB
#include <bits/stdc++.h>
using namespace std;

long long memo[305][305][305][3][2];
const long long MOD = 1000000007LL;

int 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;
        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;
        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;
            return memo[p12][p13][p23][cur][disc] = ans;
        }
    }
}

int match[305];

int main(){
    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("%d\n",func(c12,c13,c23,0,true));
    }
}

Compilation message

fishing.cpp: In function 'int func(int, int, int, int, bool)':
fishing.cpp:56:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
fishing.cpp: In function 'int main()':
fishing.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&T);
     ~~~~~^~~~~~~~~~~~~~
fishing.cpp:69:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&t);match[t] = 0;
             ~~~~~^~~~~~~~~
fishing.cpp:73:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&t);
             ~~~~~^~~~~~~~~
fishing.cpp:81:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&t);
             ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 272 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 255 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 254 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 249 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 253 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 254 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 254 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 252 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 253 ms 524288 KB Execution killed with signal 9 (could be triggered by violating memory limits)