Submission #274219

# Submission time Handle Problem Language Result Execution time Memory
274219 2020-08-19T10:01:04 Z Atill83 Fishing Game (RMI19_fishing) C++14
10 / 100
190 ms 55772 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;
int dp[105][105][105][3][2];

int 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;
    int &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
}
# Verdict Execution time Memory Grader output
1 Correct 26 ms 27520 KB Output is correct
2 Incorrect 30 ms 27520 KB Output isn't correct
3 Incorrect 30 ms 27520 KB Output isn't correct
4 Incorrect 31 ms 27520 KB Output isn't correct
5 Incorrect 85 ms 27520 KB Output isn't correct
6 Runtime error 151 ms 55772 KB Execution killed with signal 11
7 Runtime error 190 ms 55672 KB Execution killed with signal 11
8 Runtime error 166 ms 55672 KB Execution killed with signal 11
9 Runtime error 72 ms 55672 KB Execution killed with signal 11
10 Runtime error 91 ms 55692 KB Execution killed with signal 11