Submission #259627

# Submission time Handle Problem Language Result Execution time Memory
259627 2020-08-08T05:32:08 Z dantoh000 Fishing Game (RMI19_fishing) C++14
100 / 100
194 ms 202828 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int mem[3][205][205][205][2];
const int mod = 1000000007;
int dp(int turn, int n01, int n02, int n12, int mustdie){
    if (n01 == 0 && n02 == 0 && n12 == 0) return 1;
    if (mem[turn][n01][n02][n12][mustdie] != -1) return mem[turn][n01][n02][n12][mustdie];
    //printf("start %d %d %d %d %d\n",turn,n01,n02,n12,mustdie);
    ll ret = 0;
    if (turn == 0){
        if (n01) ret += (ll)n01*dp(1, n01-1, n02,   n12,         0);
        if (n02) ret += (ll)n02*dp(1, n01,   n02-1, n12+1, mustdie);
        if (n01 == 0 && n02 == 0) ret += dp(1, n01, n02, n12, mustdie);
    }
    if (turn == 1){
        if (n12) ret += (ll)n12*dp(2, n01  , n02,   n12-1,       0);
        if (n01) ret += (ll)n01*dp(2, n01-1, n02+1, n12,   mustdie);
        if (n12 == 0 && n01 == 0) ret += dp(2, n01, n02, n12, mustdie);
    }
    if (turn == 2){
        if (mustdie){
            if (n02 == 0) ret = 0;
            else ret = (ll)n02*dp(0, n01, n02-1, n12, 1);
        }
        else{
            if (n12) ret += (ll)n12*dp(0, n01+1, n02,   n12-1, 1);
            if (n02) ret += (ll)n02*dp(0, n01  , n02-1, n12,   1);
            if (n12 == 0 && n02 == 0) ret += dp(0, n01, n02, n12, 1);
        }
    }
    ret %= mod;
    //printf("%d %d %d %d %d: %lld\n",turn,n01,n02,n12,mustdie,ret);
    return mem[turn][n01][n02][n12][mustdie] = (int)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 %d %d\n",n01,n02,n12);
        printf("%d\n",dp(0,n01,n02,n12,1));
    }
}

Compilation message

fishing.cpp: In function 'int main()':
fishing.cpp:39: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:45:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x);
             ~~~~~^~~~~~~~~
fishing.cpp:49:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x);
             ~~~~~^~~~~~~~~
fishing.cpp:53:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x);
             ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 101 ms 202616 KB Output is correct
2 Correct 104 ms 202572 KB Output is correct
3 Correct 106 ms 202616 KB Output is correct
4 Correct 102 ms 202616 KB Output is correct
5 Correct 112 ms 202744 KB Output is correct
6 Correct 126 ms 202616 KB Output is correct
7 Correct 134 ms 202744 KB Output is correct
8 Correct 152 ms 202684 KB Output is correct
9 Correct 176 ms 202828 KB Output is correct
10 Correct 194 ms 202616 KB Output is correct