Submission #19678358


Source Code Expand

Copy
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>
#include <functional>
#include <cassert>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ld = long double;
using vld = vector<ld>;
using vb = vector<bool>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

template <class T> bool chmin(T& a, T b) {
    if(a > b) { a = b; return true; }
    else return false;
}

template <class T> bool chmax(T& a, T b) {
    if(a < b) { a = b; return true; }
    else return false;
}

template <class T> ostream& operator<<(ostream& s, const vector<T>& a) {
    for(auto i : a) s << i << ' ';
    return s;
}

constexpr ll INFL = 1LL << 60;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct mint {
    static const long long mod = 1000000007;
    long long x;
    mint(long long x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint& a) {if ((x += a.x) >= mod) x -= mod; return *this;}
    mint& operator-=(const mint& a) {if ((x += mod - a.x) >= mod) x -= mod; return *this;}
    mint& operator*=(const mint& a) {(x *= a.x) %= mod; return *this;}

    friend const mint operator+(const mint& a, const mint& b) { mint ret = a; return ret += b; }
    friend const mint operator-(const mint& a, const mint& b) { mint ret = a; return ret -= b; }
    friend const mint operator*(const mint& a, const mint& b) { mint ret = a; return ret *= b; }
    friend ostream& operator<<(ostream& s, const mint& a) { return s << a.x; }

    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2);}
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    friend const mint operator/(const mint& a, const mint& b) { mint ret = a; return ret /= b; }
};

struct combi {
    const static long long mod = mint::mod;
    int n;
    vector<mint> fac, finv, inv;
    
    combi(int _n) : n(_n + 1), fac(n, 1), finv(n, 1), inv(n, 1) {
        for (int i = 2; i < n; ++i) {
            fac[i] = fac[i - 1] * i;
            inv[i] =- inv[mod % i] * (mod / i);
            finv[i] = finv[i - 1] * inv[i];
        }
    };

    mint get(int n, int k) {
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        mint ret = fac[n] * finv[k] * finv[n - k];
        return ret;
    }
};

using vm = vector<mint>;

void solve() {
    vll f(26);
    ll sumf = 0;
    rep(i, 26) {
        cin >> f[i];
        if(f[i] > 0) sumf += f[i] - 1;
    }
    int sz = sumf + 1;
    vm dp(sz);
    dp[0] = 1;
    combi com(1000);
    sumf = 0;
    rep(i, 26) {
        if(f[i] == 0) continue;
        vm ndp(sz);
        for(int j = 0; j < sz; ++j) {
            if(dp[j].x == 0) continue;
            if(sumf+1-j < 0) break;
            for(int k = 1; k <= f[i]; ++k) {    // 文字の固まりの数
                mint fn = com.get(f[i]-1, k-1);
//                assert(fn.x < 100);
                int addj = f[i] - k;
                for(int subj = 0; subj <= min(j, k); ++subj) {
                    if(j-subj+addj >= sz) continue;
                    if(j-subj+addj < 0) break;
                    if(j < subj) break;
                    mint subn;
                    if(j > 0) subn = com.get(j, subj);
                    else subn = 1;
//                    assert(subn.x < 100);
                    mint noch;
                    if(sumf+1-j > 0) noch = com.get(sumf+1-j, k-subj);
                    else noch = 1;
//                    assert(noch.x < 100);
//                    cout << "add dp: " << dp[j] * fn * subn * noch << endl;;
                    assert(j-subj+addj >= 0 && j-subj+addj < sz);
                    ndp[j-subj+addj] += dp[j] * fn * subn * noch;
//                    cout << "idx: " << j << ' ' << k << ' ' << subj << endl;
//                    cout << subn << ' ' << noch << ' ' << dp[j] << ' ' << fn << endl;
                }
//                cout << "k=" << k << ' ' << ndp << endl;
            }
        }
        sumf += f[i];
        swap(dp, ndp);
//        cout << dp << endl;
    }
    cout << dp[0] << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Submission Info

Submission Time
Task O - 文字列
User Yoko_303
Language C++ (GCC 9.2.1)
Score 6
Code Size 5040 Byte
Status AC
Exec Time 11 ms
Memory 3504 KB

Judge Result

Set Name All
Score / Max Score 6 / 6
Status
AC × 4
Set Name Test Cases
All 00, 01, 90, 91
Case Name Status Exec Time Memory
00 AC 11 ms 3452 KB
01 AC 4 ms 3472 KB
90 AC 2 ms 3504 KB
91 AC 3 ms 3472 KB