比赛 2024暑期C班集训1 评测结果 AAAAAAWWWWTTTTTTTTTW
题目名称 艾姆易艾克斯 最终得分 30
用户昵称 liuyiche 运行时间 9.008 s
代码语言 C++ 内存使用 3.52 MiB
提交时间 2024-07-01 11:12:41
显示代码纯文本
    #include <bits/stdc++.h>
                    
    using namespace std;
        
    int n, ans = 0, Min = 1e9;     
    int a[100010];
    int b[100010];
    int mod = 1e9+7;
    bool tp = true;
    int m[100005];
     
    inline int qpow(int x, int p)
    {
        if(p == 0)
             return 1;
        int tmp = qpow(x,p/2);
        tmp %= mod;
        tmp *= tmp;
        tmp %= mod;
        if(p % 2 != 0)
        tmp *= x;
        tmp %= mod;
        return tmp;
    }
     
    inline void dfs(int step)
    {
        if(step == n+1)
        {
            int tmp;
            for(int i = 0; i <= 100002; ++i)
                if(m[i] == 0)
                {
                    tmp = i;
                    break;
                }
            if(tmp == Min)
                ans++, ans %= mod;
            else if(tmp < Min)
                Min = tmp, ans = 1;
            return;
        }
        dfs(step+1);
        if(a[step] <= 100000)
        m[a[step]]--;
        if(b[step] <= 100000)
        m[b[step]]++;
        dfs(step+1);
        if(a[step] <= 100000)
        m[a[step]]++;
        if(b[step] <= 100000)
        m[b[step]]--;
    }
            
    int main()
    {
        freopen("Mex.in", "r", stdin);
        freopen("Mex.out", "w", stdout);
                
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
                    
        cin >> n;
        for(int i = 1; i <= n; ++i)
            cin >> a[i];
        for(int i = 1; i <= n; ++i)
        {
            cin >> b[i];
            if(b[i] != a[i])
                tp = false;
        }
        for(int i = 1; i <= n; ++i)
                if(a[i] <= 100000)
                    m[a[i]]++;
        if(tp == true)
        {
            for(int i = 0; i <= 100002; ++i)
                if(m[i] == 0)
                {
                    cout << i << " ";
                    break;
                }
            cout << qpow(2,n);
            return 0;
        }
        
        dfs(1);
        cout << Min << " " << ans;
            
       	return 0;
    }