답안 #238515

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
238515 2020-06-11T15:28:55 Z Sorting Fishing Game (RMI19_fishing) C++14
0 / 100
57 ms 57184 KB
#include <bits/stdc++.h>

using namespace std;

const int k_Mod = 1e9 + 7;
const int k_N = 100 + 3;

int n;
pair<int, bool> dp[3 * k_N][3 * k_N][3 * k_N][3];

int get_answer(int ab, int ac, int bc, int stage){
    if(ab + ac + bc == 0)
        return 1;

    //cout << ab << " " << ac << " " << bc << " " << stage << endl;

    auto &[answer, solved] = dp[ab][ac][bc][stage];
    if(solved)
        return answer;

    solved = true;
    answer = 0;

    if(stage == 0){
        if(ab + ac == 0)
            return answer = get_answer(ab, ac, bc, 1);

        if(ab)  answer += get_answer(ab - 1, ac, bc, 1) * ab % k_Mod;
        if(ac)  answer += get_answer(ab, ac - 1, bc + 1, 1) * ac % k_Mod;
        return answer %= k_Mod;
    }
    if(stage == 1){
        if(ab + bc == 0)
            return answer = get_answer(ab, ac, bc, 2);

        if(ab)  answer += get_answer(ab - 1, ac + 1, bc, 2) * ab % k_Mod;
        if(bc)  answer += get_answer(ab, ac, bc - 1, 2) * bc % k_Mod;
        return answer %= k_Mod;
    }
    if(stage == 2){
        if(ac + bc == 0)
            return answer = get_answer(ab, ac, bc, 0);

        if(ac)  answer += get_answer(ab, ac - 1, bc, 0) * ac % k_Mod;
        if(bc)  answer += get_answer(ab + 1, ac, bc - 1, 0) * bc % k_Mod;
        return answer %= k_Mod;
    }

    assert(false);
}

void solve_test(){
    static pair<int, int> pos[3 * k_N];

    for(int i = 1; i <= 3 * n; ++i)
        pos[i] = {0, 0};

    int x;
    for(int i = 0; i < 2 * n; ++i){
        cin >> x;
        if(!pos[x].first)
            pos[x].first = 0;
        else
            pos[x].second = 0;
    }
    for(int i = 0; i < 2 * n; ++i){
        cin >> x;
        if(!pos[x].first)
            pos[x].first = 1;
        else
            pos[x].second = 1;
    }
    for(int i = 0; i < 2 * n; ++i){
        cin >> x;
        if(!pos[x].first)
            pos[x].first = 2;
        else
            pos[x].second = 2;
    }

    int ab = 0, ac = 0, bc = 0;
    for(int i = 1; i <= 3 * n; ++i){
        if(pos[i].first == pos[i].second)
            continue;

        if(pos[i].first > pos[i].second)
            swap(pos[i].first, pos[i].second);

        if(pos[i].second == 1)
            ab++;
        else if(pos[i].first == 0)
            ac++;
        else
            bc++;
    }

    //cout << ab << " " << ac << " " << bc << endl;

    //cout << get_answer(ab, ac, bc, 0) << "\n";
    exit(get_answer(ab, ac, bc, 0));
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> n >> t;

    while(t--)
        solve_test();
}

Compilation message

fishing.cpp: In function 'int get_answer(int, int, int, int)':
fishing.cpp:17:11: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
     auto &[answer, solved] = dp[ab][ac][bc][stage];
           ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 384 KB Execution failed because the return code was nonzero
2 Runtime error 4 ms 384 KB Execution failed because the return code was nonzero
3 Runtime error 5 ms 1024 KB Execution failed because the return code was nonzero
4 Runtime error 6 ms 1408 KB Execution failed because the return code was nonzero
5 Runtime error 12 ms 10240 KB Execution failed because the return code was nonzero
6 Runtime error 20 ms 18048 KB Execution failed because the return code was nonzero
7 Runtime error 20 ms 16640 KB Execution failed because the return code was nonzero
8 Runtime error 30 ms 29568 KB Execution failed because the return code was nonzero
9 Runtime error 50 ms 48888 KB Execution failed because the return code was nonzero
10 Runtime error 57 ms 57184 KB Execution failed because the return code was nonzero