結果

問題 No.2033 Chromatic Duel
ユーザー 👑 NachiaNachia
提出日時 2022-08-05 22:40:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 2,969 bytes
コンパイル時間 779 ms
コンパイル使用メモリ 81,436 KB
実行使用メモリ 5,500 KB
最終ジャッジ日時 2023-10-14 00:11:26
合計ジャッジ時間 2,710 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,192 KB
testcase_01 AC 7 ms
5,468 KB
testcase_02 AC 6 ms
5,312 KB
testcase_03 AC 6 ms
5,192 KB
testcase_04 AC 6 ms
5,500 KB
testcase_05 AC 7 ms
5,284 KB
testcase_06 AC 7 ms
5,324 KB
testcase_07 AC 7 ms
5,292 KB
testcase_08 AC 6 ms
5,168 KB
testcase_09 AC 6 ms
5,168 KB
testcase_10 AC 6 ms
5,364 KB
testcase_11 AC 6 ms
5,216 KB
testcase_12 AC 7 ms
5,376 KB
testcase_13 AC 7 ms
5,328 KB
testcase_14 AC 7 ms
5,312 KB
testcase_15 AC 7 ms
5,392 KB
testcase_16 AC 6 ms
5,436 KB
testcase_17 AC 6 ms
5,392 KB
testcase_18 AC 6 ms
5,300 KB
testcase_19 AC 6 ms
5,280 KB
testcase_20 AC 6 ms
5,216 KB
testcase_21 AC 8 ms
5,432 KB
testcase_22 AC 8 ms
5,328 KB
testcase_23 AC 6 ms
5,192 KB
testcase_24 AC 6 ms
5,192 KB
testcase_25 AC 7 ms
5,296 KB
testcase_26 AC 6 ms
5,424 KB
testcase_27 AC 6 ms
5,232 KB
testcase_28 AC 7 ms
5,192 KB
testcase_29 AC 6 ms
5,308 KB
testcase_30 AC 6 ms
5,360 KB
testcase_31 AC 6 ms
5,360 KB
testcase_32 AC 7 ms
5,188 KB
testcase_33 AC 7 ms
5,364 KB
testcase_34 AC 6 ms
5,328 KB
testcase_35 AC 6 ms
5,432 KB
testcase_36 AC 7 ms
5,336 KB
testcase_37 AC 7 ms
5,400 KB
testcase_38 AC 6 ms
5,212 KB
testcase_39 AC 7 ms
5,404 KB
testcase_40 AC 6 ms
5,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "Main.cpp"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>

#line 2 "nachia\\math\\combination.hpp"

#line 4 "nachia\\math\\combination.hpp"


namespace nachia{

template<class Modint>
class Comb{
private:
    ::std::vector<Modint> F;
    ::std::vector<Modint> iF;
public:
    Comb(int n){
        F.assign(n+1, Modint(1));
        for(int i=1; i<=n; i++) F[i] = F[i-1] * Modint(i);
        iF.assign(n+1, Modint(1));
        iF[n] = F[n].inv();
        for(int i=n; i>=1; i--) iF[i-1] = iF[i] * Modint(i);
    }
    Modint factorial(int n) const { return F[n]; }
    Modint inv_factorial(int n) const { return iF[n]; }
    Modint inv_of(int n) const { return iF[n] * F[n-1]; }
    Modint comb(int n, int r) const {
        if(n < 0 || n < r || r < 0) return Modint(0);
        return F[n] * iF[r] * iF[n-r];
    }
    Modint inv_comb(int n, int r) const {
        if(n < 0 || n < r || r < 0) return Modint(0);
        return iF[n] * F[r] * F[n-r];
    }
    Modint perm(int n, int r) const {
        if(n < 0 || n < r || r < 0) return Modint(0);
        return F[n] * iF[n-r];
    }
    Modint inv_perm(int n, int r) const {
        if(n < 0 || n < r || r < 0) return Modint(0);
        return iF[n] * F[n-r];
    }
    Modint operator()(int n, int r) const { return comb(n,r); }
};

} // namespace nachia
#line 8 "Main.cpp"
//#include "nachia/fps/formal-power-series-struct.hpp"

using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)


const i64 INF = 1001001001001001001;
//using FPS = nachia::FormalPowerSeriesNTT<998244353>;
using modint = atcoder::static_modint<998244353>;
//using modint = FPS::Elem;

auto comb = nachia::Comb<modint>(300000);

modint solve(int N, int B, int W){
    //cout << "solve(" << N << ", " << B << ", " << W << ")" << endl;
    N -= B;
    B++;
    //cout << "N = " << N << " , B = " << B << " , W = " << W << endl;
    modint ans = 0;
    for(int a=0; a<=B; a++){
        int b = W - (N-2*(B-a));
        int c = B - a - b;
        if(b < 0 || c < 0 || b + 2*c + W != N) continue;
        //cout << "   a = " << a << " , b = " << b << " , c = " << c << endl;
        if(c != 0) ans += comb(B, a) * comb(B-a, b) * comb(W+c-1, c-1);
        else if(W == 0) ans += comb(B, a) * comb(B-a, b);
    }
    //cout << "ans = " << ans.val() << '\n';
    return ans;
}

int main(){
    int N, B, W; cin >> N >> B >> W;
    if(B == 1){
        if(W == N - 2){ cout << 2 << '\n'; }
        else if(W == N - 3){ cout << (N-2) << '\n'; }
        else{ cout << 0 << '\n'; }
    }
    else{
        modint ans = solve(N+2, B, W) - solve(N+1, B-1, W) * 2 + solve(N, B-2, W);
        cout << ans.val() << '\n';
    }
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;


0