提出 #65652737


ソースコード 拡げる

#include <bits/stdc++.h>

using namespace std;
// #define int long long 
#define sz(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

using pii = pair<int, int>;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;

const ld eps = 1e-9;
const int mod = 998244353;
const ll INF = 1e18;
const int N = 5e3 + 10;

#ifdef yb
#include "debugtemplate.cpp"
#else
#define debug(...) 
#endif

#include<atcoder/modint>
using namespace atcoder;
using mint = static_modint<mod>;
using vm = vector<mint>;
std::ostream& operator << (std::ostream& out, const mint& rhs) {
        return out<<rhs.val();
    }

// using mint = modint;
// mint::set_mod(M);

// int x.val() : returns value stored in variable
// when using (a / b or a /= b) : gcd(b.val(), mod )  = 1
// modint x.pow(ll n) : returns x^n
// modint x.inv() : returns modulo inverse

vector<mint> fact(1, 1);
vector<mint> ifact(1, 1);

mint C(int n, int k) {
  if (k < 0 || k > n) {
    return 0;
  }
  while ((int) fact.size() < n + 1) {
    fact.push_back(fact.back() * (int) fact.size());
    ifact.push_back(1 / fact.back());
  }
  return fact[n] * ifact[k] * ifact[n - k];
}

mint D (int n, int k) {
    // n slots are constrained and k are free
    mint ret = 0;
    C(n + k, 0);
    for (int i = 0; i <= n; i++) {
        mint here = fact[n + k - i];
        here *= C(n, i);
        if (i & 1)
            ret -= here;
        else
            ret += here;
    }
    return ret;
}

mint Solutions (int n, int sum, int ub = 1e9 + 7) {
    // x_1 + ... + x_n = sum
    // 0 <= x_i <= ub : pie
    mint ret = 0;
    for (int i = 0; i <= n; i++) {
        int nsum = sum - i * (ub + 1);
        if (nsum < 0) 
            break;
        if (i & 1) {
            ret -= C(n, i) * C (nsum + n - 1, n - 1);
        }
        else {
            ret += C(n, i) * C(nsum + n - 1, n - 1);
        }
    }
    return ret;
}

void Solve() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    mint ans = 0;

    for (int i = 0; i <= c; i++) {
        ans += C(a + b + i, b) * C(c - i + d - 1, d - 1);
    }
    cout << ans << endl;
}

int32_t main() {
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
     freopen("error.txt", "w", stderr);
    #endif
    int _ = 1;
    // cin >> _;
    cout << fixed;
    cout << setprecision(20);

    for(int i = 1; i <= _; i++) 
    {
        // cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}

提出情報

提出日時
問題 E - Fruit Lineup
ユーザ yb38
言語 C++ 20 (gcc 12.2)
得点 475
コード長 2915 Byte
結果 AC
実行時間 353 ms
メモリ 28104 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 475 / 475
結果
AC × 3
AC × 17
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_max_00.txt, 02_max_01.txt, 02_max_02.txt, 02_max_03.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3840 KiB
00_sample_01.txt AC 1 ms 3844 KiB
00_sample_02.txt AC 169 ms 15852 KiB
01_random_00.txt AC 238 ms 19260 KiB
01_random_01.txt AC 160 ms 15696 KiB
01_random_02.txt AC 198 ms 16916 KiB
01_random_03.txt AC 69 ms 9440 KiB
01_random_04.txt AC 157 ms 15768 KiB
01_random_05.txt AC 278 ms 28104 KiB
01_random_06.txt AC 208 ms 17840 KiB
01_random_07.txt AC 96 ms 10040 KiB
01_random_08.txt AC 118 ms 11548 KiB
01_random_09.txt AC 116 ms 11552 KiB
02_max_00.txt AC 351 ms 28060 KiB
02_max_01.txt AC 353 ms 28012 KiB
02_max_02.txt AC 351 ms 28056 KiB
02_max_03.txt AC 352 ms 28036 KiB