답안 #274221

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
274221 2020-08-19T10:02:18 Z Atill83 Fishing Game (RMI19_fishing) C++14
50 / 100
342 ms 110848 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
ll dp[105][105][105][3][2];

ll d(int ab, int ac, int bc, int step, bool done){
    if(ab < 0 || ac < 0 || bc < 0) return 0;
    if(ab + ac + bc == 0) return 1;
    ll &r = dp[ab][ac][bc][step][done];
    if(r != -1) return r;

    r = 0;

    if(step == 0){
        if(ab + ac == 0){
            r = d(ab, ac, bc, 1, 0);
        }else{
            r = (r + ac*d(ab, ac - 1, bc + 1, 1, 0)%mod)%mod;
            r = (r + ab*d(ab - 1, ac, bc, 1, 1)%mod)%mod;
        }
    }else if(step == 1){
        if(ab + bc == 0){
            r = d(ab, ac, bc, 2, done);
        }else{
            r = (r + ab*d(ab - 1, ac + 1, bc, 2, done)%mod)%mod;
            r = (r + bc*d(ab, ac, bc - 1, 2, 1)%mod)%mod;
        }
    }else if(step == 2){
        if(ac == 0 && done == 0){
            return r = 0;
        }else if(ac + bc == 0){
            r = d(ab, ac, bc, 0, 0);
        }else{
            r = (r + bc*d(ab + 1, ac, bc - 1, 0, 0)%mod)%mod;
            r = (r + ac*d(ab, ac - 1, bc, 0, 0)%mod) % mod;
        }
    }

    return r;
}



void solve(){
    set<int> a, b, c;

    for(int i = 0; i < 2*n; i++){
        int k;
        cin>>k;
        auto u = a.find(k);
        if(u != a.end()){
            a.erase(u);
            continue;
        }
        a.insert(k);
    }

    
    for(int i = 0; i < 2*n; i++){
        int k;
        cin>>k;
        auto u = b.find(k);
        if(u != b.end()){
            b.erase(u);
            continue;
        }
        b.insert(k);
    }

    
    for(int i = 0; i < 2*n; i++){
        int k;
        cin>>k;
        auto u = c.find(k);
        if(u != c.end()){
            c.erase(u);
            continue;
        }
        c.insert(k);
    }

    int ab = 0, ac = 0, bc = 0;

    for(int u: a){
        if(b.find(u) != b.end()){
            ab++;
            b.erase(u);
        }else if(c.find(u) != c.end()){
            ac++;
        }
    }
    for(int u: b){
        if(c.find(u) != c.end()) bc++;
    }



    memset(dp, -1, sizeof(dp));

    cout<<d(ab, ac, bc, 0, 0)<<endl;

}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif
    int t;
    cin>>n>>t;

    while(t--)
        solve();

    

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 54648 KB Output is correct
2 Correct 61 ms 54656 KB Output is correct
3 Correct 64 ms 54648 KB Output is correct
4 Correct 65 ms 54656 KB Output is correct
5 Correct 163 ms 54868 KB Output is correct
6 Runtime error 337 ms 110840 KB Execution killed with signal 11
7 Runtime error 342 ms 110712 KB Execution killed with signal 11
8 Runtime error 167 ms 110712 KB Execution killed with signal 11
9 Runtime error 135 ms 110712 KB Execution killed with signal 11
10 Runtime error 141 ms 110848 KB Execution killed with signal 11