Submission #709684

# Submission time Handle Problem Language Result Execution time Memory
709684 2023-03-14T07:33:13 Z Nursik W (RMI18_w) C++17
35 / 100
600 ms 9944 KB
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <functional>
#include <complex>
#include <random>
 
using namespace std;
 
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
 
const ll maxn = 1e6 + 1, maxm = 3e4 + 1;
const ll mod = 1e9 + 7, cmod = 998244353, inf = 1e9, block = 5000, p2 = 31, bit = 30;
const ld eps = 1e-9;

int n;
int a[maxn];
ll fact[maxn];
int cnt[maxn];
ll dp[(1 << 5)];
vector<pair<int, pair<int, int>>> go[(1 << 5)];
ll bp(ll a, ll n){
    ll res = 1;
    while (n > 0){
        if (n & 1){
            res *= a;
        }
        a *= a, n >>= 1;
        a %= mod, res %= mod;
    }
    return res;
}
ll cnk(int n, int k){
    if (n < k)
        return 0;
    return fact[n] * bp(fact[k], mod - 2) % mod * bp(fact[n - k], mod - 2) % mod;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);

    vector<int> masks;
    /*
    00000 - 0
    01000 - 2
    00010 - 8
    11000 - 3
    00011 - 24
    01010 - 10
    11010 - 11
    01011 - 26
    11011 - 27
    01110 - 14
    11110 - 15
    01111 - 30
    11111 - 31
     */
    masks.pb(0);
    masks.pb(2);
    masks.pb(8);
    masks.pb(3);
    masks.pb(24);
    masks.pb(10);
    masks.pb(11);
    masks.pb(26);
    masks.pb(27);
    masks.pb(14);
    masks.pb(15);
    masks.pb(30);
    masks.pb(31);

    go[0].pb(mp(2, mp(1, 1)));
    go[0].pb(mp(8, mp(1, 1)));
    go[0].pb(mp(10, mp(2, 2)));

    go[2].pb(mp(2, mp(1, 0)));
    go[2].pb(mp(10, mp(2, 1)));
    go[2].pb(mp(3, mp(2, 1)));
    go[2].pb(mp(11, mp(3, 2)));

    go[8].pb(mp(8, mp(1, 0)));
    go[8].pb(mp(10, mp(2, 1)));
    go[8].pb(mp(24, mp(2, 1)));
    go[8].pb(mp(26, mp(3, 2)));

    go[10].pb(mp(10, mp(2, 0)));
    go[10].pb(mp(11, mp(3, 1)));
    go[10].pb(mp(26, mp(3, 1)));
    go[10].pb(mp(30, mp(2, 2)));
    go[10].pb(mp(31, mp(3, 3)));
    go[10].pb(mp(27, mp(4, 2)));
    go[10].pb(mp(14, mp(3, 1)));
    go[10].pb(mp(15, mp(2, 2)));

    go[3].pb(mp(3, mp(2, 0)));
    go[3].pb(mp(11, mp(3, 1)));

    go[24].pb(mp(24, mp(2, 0)));
    go[24].pb(mp(26, mp(3, 1)));

    go[26].pb(mp(26, mp(3, 0)));
    go[26].pb(mp(30, mp(2, 1)));
    go[26].pb(mp(27, mp(4, 1)));
    go[26].pb(mp(31, mp(3, 2)));
    
    go[11].pb(mp(11, mp(3, 0)));
    go[11].pb(mp(15, mp(2, 1)));
    go[11].pb(mp(27, mp(4, 1)));
    go[11].pb(mp(31, mp(3, 2)));

    go[27].pb(mp(27, mp(4, 0)));
    go[27].pb(mp(31, mp(3, 1)));

    go[14].pb(mp(31, mp(2, 2)));
    go[14].pb(mp(30, mp(1, 1)));
    go[14].pb(mp(15, mp(1, 1)));

    go[15].pb(mp(15, mp(1, 0)));
    go[15].pb(mp(31, mp(2, 1)));

    go[30].pb(mp(30, mp(1, 0)));
    go[30].pb(mp(31, mp(2, 1)));

    go[31].pb(mp(31, mp(2, 0)));
    cin >> n;
    fact[0] = 1;
    for (int i = 1; i <= n; ++i){
        cin >> a[i];
        cnt[a[i]] += 1;
        fact[i] = fact[i - 1] * i % mod;
    }
    sort(a + 1, a + n + 1);
    vector<int> v;
    for (int i = 1; i <= n; ++i){
        if (a[i] != a[i - 1]){
            v.pb(a[i]);
        }
    }
    n = 0;
    for (auto it : v){
        a[++n] = it;
    }
    dp[0] = 1;
    reverse(masks.begin(), masks.end());
    for (int i = 1; i <= n; ++i){
        if (cnt[a[i]] > 0){
            for (auto it : masks){
                if (dp[it] > 0){
                    ll x = dp[it];
                    dp[it] = 0;
                    for (auto msk2 : go[it]){
                        pair<int, pair<int, int>> cur = msk2;
                        int gmask = cur.f;
                        int allbits = cur.s.f;
                        int nbits = cur.s.s;
                        dp[gmask] = (dp[gmask] + x * cnk(cnt[a[i]] - nbits + allbits - 1, allbits - 1) % mod) % mod;
                    }
                }
            }
            cnt[a[i]] = 0;
        }
    }
    cout << dp[(1 << 5) - 1];
} 




# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 6 ms 852 KB Output is correct
4 Correct 27 ms 3780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 10 ms 412 KB Output is correct
3 Correct 245 ms 4732 KB Output is correct
4 Execution timed out 859 ms 5968 KB Time limit exceeded
5 Execution timed out 1078 ms 5708 KB Time limit exceeded
6 Execution timed out 1078 ms 9944 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Incorrect 4 ms 340 KB Output isn't correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Incorrect 37 ms 468 KB Output isn't correct
7 Incorrect 49 ms 852 KB Output isn't correct
8 Incorrect 12 ms 1832 KB Output isn't correct
9 Incorrect 33 ms 2700 KB Output isn't correct
10 Execution timed out 1093 ms 9928 KB Time limit exceeded