Submission #207159

# Submission time Handle Problem Language Result Execution time Memory
207159 2020-03-06T15:15:36 Z mayhoubsaleh Fishing Game (RMI19_fishing) C++14
0 / 100
589 ms 129016 KB
#include <bits/stdc++.h>
#include <string>
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;
const int mod=1e9+7;
int n;
int dp[3][222][222][222];
map<int,int>m[3];
int cnt[3];
int sz[3];

int f(int pl,int cnt[],int sz[]){
    int &ans=dp[pl][cnt[0]][cnt[1]][cnt[2]];
    if(ans+1)return ans;
    ans=0;
    if(!sz[pl])return ans=1;
    if(cnt[pl]){
        cnt[pl]--;
        sz[pl]--;
        sz[(pl+1)%3]--;
        ans=(ans+(cnt[pl]+1)*f((pl+1)%3,cnt,sz)%mod)%mod;
        sz[(pl+1)%3]++;
        sz[pl]++;
        cnt[pl]++;
    }
    if(sz[pl]-cnt[pl]){
        int x=sz[pl]-cnt[pl];
        cnt[(pl+1)%3]++;
        cnt[(pl+2)%3]--;
        sz[pl]--;
        sz[(pl+1)%3]++;
        ans=(ans+x*f((pl+1)%3,cnt,sz)%mod)%mod;
        cnt[(pl+1)%3]--;
        cnt[(pl+2)%3]++;
        sz[pl]++;
        sz[(pl+1)%3]--;
    }
    return ans;
}
void solve(){
    for(int i=0;i<3;i++){
        for(int j=0;j<2*n;j++){
            int x;
            cin>>x;
            if(m[i][x])m[i].erase(x);
            else m[i][x]=1;
        }
    }

    for(int i=0;i<3;i++){
        cnt[i]=0;
        sz[i]=0;
        for(auto x:m[i]){
            if(!x.second)continue;
            sz[i]++;
            if(m[(i+1)%3][x.first])cnt[i]++;
        }
        //cout<<cnt[i]<<' '<<sz[i]<<endl;
    }
    memset(dp,-1,sizeof dp);
    cout<<f(0,cnt,sz)<<endl;
}
int main()
{
    IOS
    int t;
    cin>>n;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 108 ms 128760 KB Output isn't correct
2 Incorrect 144 ms 128760 KB Output isn't correct
3 Incorrect 145 ms 128760 KB Output isn't correct
4 Incorrect 148 ms 128760 KB Output isn't correct
5 Incorrect 277 ms 129016 KB Output isn't correct
6 Incorrect 301 ms 128888 KB Output isn't correct
7 Incorrect 337 ms 128888 KB Output isn't correct
8 Incorrect 403 ms 128888 KB Output isn't correct
9 Incorrect 505 ms 129016 KB Output isn't correct
10 Incorrect 589 ms 128888 KB Output isn't correct