답안 #331396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
331396 2020-11-28T10:26:27 Z evpipis Fishing Game (RMI19_fishing) C++11
100 / 100
108 ms 33644 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
const int len = 105, mod = 1e9+7;
int dp[2*len][2*len][2*len];
vector<int> vec[3*len];

int add(int a, int b){
    return (a+b)%mod;
}

int mul(int a, int b){
    return (a*1LL*b)%mod;
}

int solve(int x, int y, int z){
    if (x == 0 && y == 0 && z == 0)
        return 1;
    if (dp[x][y][z] != -1)
        return dp[x][y][z];

    int ans = 0;
    for (int bit = 1; bit < (1<<3); bit++){
        int s[] = {x, y, z};

        int c = 1;
        for (int i = 0; i < 3; i++){
            if ((bit&(1<<i)) && s[i] > 0)
                c = mul(c, s[i]), s[i]--;
            else if (!(bit&(1<<i)) && s[(i+2)%3] > 0)
                c = mul(c, s[(i+2)%3]), s[(i+2)%3]--, s[(i+1)%3]++;
            else if (!(bit&(1<<i)) && s[(i+2)%3] == 0 && s[i] == 0)
                continue;
            else
                c = 0;
        }

        if (c > 0)
            ans = add(ans, mul(c, solve(s[0], s[1], s[2])));
    }

    //printf("solve(%d, %d, %d) = %d\n", x, y, z, ans);

    return dp[x][y][z] = ans;
}

int main(){
    int n, t;
    scanf("%d %d", &n, &t);

    for (int x = 0; x <= 2*n; x++)
        for (int y = 0; y <= 2*n; y++)
            for (int z = 0; z <= 2*n; z++)
                dp[x][y][z] = -1;

    /*for (int x = 0; x <= 2*n; x++)
        for (int y = 0; y <= 2*n; y++)
            for (int z = 0; z <= 2*n; z++)
                if (x+y+z <= 6*n)
                    solve(x, y, z);*/

    for (int test = 0; test < t; test++){
        for (int card = 1; card <= 3*n; card++)
            vec[card].clear();

        for (int c = 0; c < 3; c++){
            for (int i = 0; i < 2*n; i++){
                int card;
                scanf("%d", &card);
                vec[card].pb(c);
            }
        }

        int x = 0, y = 0, z = 0;
        for (int card = 1; card <= 3*n; card++){
            int a = vec[card][0], b = vec[card][1];
            if (a > b) swap(a, b);

            if (a == 0 && b == 1) x++;
            if (a == 1 && b == 2) y++;
            if (a == 0 && b == 2) z++;
        }

        //printf("x = %d, y = %d, z = %d\n", x, y, z);

        printf("%d\n", solve(x, y, z));
    }

    return 0;
}
/*
1 1
1 1
2 3
2 3
*/

Compilation message

fishing.cpp: In function 'int main()':
fishing.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   50 |     scanf("%d %d", &n, &t);
      |     ~~~~~^~~~~~~~~~~~~~~~~
fishing.cpp:70:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   70 |                 scanf("%d", &card);
      |                 ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 2 ms 1900 KB Output is correct
5 Correct 17 ms 9068 KB Output is correct
6 Correct 28 ms 12908 KB Output is correct
7 Correct 41 ms 17260 KB Output is correct
8 Correct 59 ms 22380 KB Output is correct
9 Correct 85 ms 28012 KB Output is correct
10 Correct 108 ms 33644 KB Output is correct