답안 #259620

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259620 2020-08-08T05:15:25 Z dantoh000 Fishing Game (RMI19_fishing) C++14
0 / 100
263 ms 524292 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mem[3][305][305][305][2];
const int mod = 1000000007;
ll dp(int turn, int n01, int n02, int n12, int mustdie){
    if (n01 == 0 && n02 == 0 && n12 == 0) return 1;
    else if (mem[turn][n01][n02][n12][mustdie] != -1) return mem[turn][n01][n02][n12][mustdie];
    ll ret = 0;
    if (turn == 0){
        if (n01) ret += n01*dp(1, n01-1, n02,   n12,         0);
        if (n02) ret += n02*dp(1, n01,   n02-1, n12+1, mustdie);
    }
    if (turn == 1){
        if (n12) ret += n12*dp(2, n01  , n02,   n12-1,       0);
        if (n01) ret += n02*dp(2, n01-1, n02+1, n12,   mustdie);
    }
    if (turn == 2){
        if (mustdie){
            if (n02 == 0) ret = 0;
            else ret = n02*dp(0, n01, n02-1, n12, 1);
        }
        else{
            if (n12) ret += n12*dp(0, n01+1, n02,   n12-1, 1);
            if (n02) ret += n02*dp(0, n01  , n02-1, n12,   1);
        }
    }
    ret %= mod;
    return mem[turn][n01][n02][n12][mustdie] = ret;
}
int a[305], b[305], c[305];
int main(){
    int n,t;
    scanf("%d%d",&n,&t);
    memset(mem,-1,sizeof(mem));
    while (t--){
        for (int i = 1; i <= 3*n; i++){ a[i] = b[i] = c[i] = 0; }
        int x;
        for (int i = 0; i < 2*n; i++){
            scanf("%d",&x);
            a[x] = 1;
        }
        for (int i = 0; i < 2*n; i++){
            scanf("%d",&x);
            b[x] = 1;
        }
        for (int i = 0; i < 2*n; i++){
            scanf("%d",&x);
            c[x] = 1;
        }
        int n01 = 0, n02 = 0, n12 = 0;
        for (int i = 1; i <= 3*n; i++){
            if (a[i] && b[i]) n01++;
            if (a[i] && c[i]) n02++;
            if (b[i] && c[i]) n12++;
        }
        printf("%d\n",dp(0,n01,n02,n12,1));
    }
}

Compilation message

fishing.cpp: In function 'int main()':
fishing.cpp:57:42: warning: format '%d' expects argument of type 'int', but argument 2 has type 'll {aka long long int}' [-Wformat=]
         printf("%d\n",dp(0,n01,n02,n12,1));
                       ~~~~~~~~~~~~~~~~~~~^
fishing.cpp:34: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:40:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x);
             ~~~~~^~~~~~~~~
fishing.cpp:44:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x);
             ~~~~~^~~~~~~~~
fishing.cpp:48:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x);
             ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 261 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 263 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 253 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 252 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 260 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 257 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 257 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 261 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 254 ms 524288 KB Execution killed with signal 9 (could be triggered by violating memory limits)