Submission #709681

#TimeUsernameProblemLanguageResultExecution timeMemory
709681NursikW (RMI18_w)C++14
30 / 100
698 ms26780 KiB
#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 = 3e5 + 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[maxn]; 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...