답안 #283930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
283930 2020-08-26T09:50:02 Z valerikk Fishing Game (RMI19_fishing) C++11
0 / 100
452 ms 223352 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int M = 1e9 + 7;
const int N = 3 * 99 + 7;

int n;
int d[N][N][N];
int w[N][2];

int dp(int n01, int n12, int n02) {
    if (~d[n01][n12][n02]) return d[n01][n12][n02];
    if (n01 == 0 && n12 == 0 && n02 == 0) return d[n01][n12][n02] = 1;
    d[n01][n12][n02] = 0;
    for (int a0 = 0; a0 < 3; ++a0) {
        if (a0 == 0 && (n01 > 0 || n02 > 0)) continue;
        if (a0 == 1 && n01 == 0) continue;
        if (a0 == 2 && n02 == 0) continue;
        int m01 = n01, m12 = n12, m02 = n02;
        int p = 1;
        if (a0 == 1) {
            p = (ll)p * m01 % M;
            m01--;
        }
        if (a0 == 2) {
            p = (ll)p * m02 % M;
            m02--;
            m12++;
        }
        for (int a1 = 0; a1 < 3; ++a1) {
            if (a1 == 1 && (m01 > 0 || m12 > 0)) continue;
            if (a1 == 0 && m01 == 0) continue;
            if (a1 == 2 && m12 == 0) continue;
            int k01 = m01, k12 = m12, k02 = m02;
            int q = p;
            if (a1 == 0) {
                q = (ll)q * k01 % M;
                k01--;
                k02++;
            }
            if (a1 == 2) {
                q = (ll)q * m12 % M;
                k12--;
            }
            for (int a2 = 0; a2 < 3; ++a2) {
                if (a2 == 2 && (k12 > 0 || k02 > 0)) continue;
                if (a2 == 0 && k02 == 0) continue;
                if (a2 == 1 && k12 == 0) continue;
                int h01 = k01, h12 = k12, h02 = k02;
                int r = q;
                if (a2 == 0) {
                    r = (ll)r * h02 % M;
                    h02--;
                }
                if (a2 == 1) {
                    r = (ll)r * h12 % M;
                    h12--;
                    h02++;
                }
                if (h01 + h12 + h02 < n01 + n12 + n02) {
                    d[n01][n12][n02] += (ll)dp(h01, h12, h02) * r % M;
                    if (d[n01][n12][n02] >= M) d[n01][n12][n02] -= M;
                }
            }
        }
    }
    return d[n01][n12][n02];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        cin >> n;
        memset(w, 255, sizeof(w));
        for (int p = 0; p < 3; ++p) {
            for (int i = 0; i < 2 * n; ++i) {
                int a;
                cin >> a;
                a--;
                if (~w[a][0]) w[a][1] = p; else w[a][0] = p;
            }
        }
        int n01 = 0, n12 = 0, n02 = 0;
        for (int i = 0; i < 3 * n; ++i) {
            if (w[i][0] == 0 && w[i][1] == 1) n01++;
            if (w[i][0] == 1 && w[i][1] == 2) n12++;
            if (w[i][0] == 0 && w[i][1] == 2) n02++;
        }
        memset(d, 255, sizeof(d));
        cout << dp(n01, n12, n02) << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 216 ms 223224 KB Execution killed with signal 11
2 Incorrect 90 ms 110456 KB Output isn't correct
3 Runtime error 295 ms 223352 KB Execution killed with signal 11
4 Runtime error 386 ms 223224 KB Execution killed with signal 11
5 Runtime error 295 ms 223352 KB Execution killed with signal 11
6 Runtime error 328 ms 223312 KB Execution killed with signal 11
7 Runtime error 386 ms 223352 KB Execution killed with signal 11
8 Runtime error 452 ms 223224 KB Execution killed with signal 11
9 Runtime error 380 ms 223224 KB Execution killed with signal 11
10 Runtime error 432 ms 223352 KB Execution killed with signal 11