結果

問題 No.1186 長方形の敷き詰め
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-08-22 14:15:46
言語 C++17(clang)
(14.0.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 2,827 bytes
コンパイル時間 1,141 ms
コンパイル使用メモリ 104,764 KB
実行使用メモリ 18,712 KB
最終ジャッジ日時 2023-08-05 11:26:21
合計ジャッジ時間 2,679 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
18,696 KB
testcase_01 AC 18 ms
18,544 KB
testcase_02 AC 18 ms
18,636 KB
testcase_03 AC 19 ms
18,636 KB
testcase_04 AC 19 ms
18,588 KB
testcase_05 AC 19 ms
18,696 KB
testcase_06 AC 19 ms
18,700 KB
testcase_07 AC 19 ms
18,696 KB
testcase_08 AC 18 ms
18,636 KB
testcase_09 AC 19 ms
18,612 KB
testcase_10 AC 18 ms
18,648 KB
testcase_11 AC 20 ms
18,704 KB
testcase_12 AC 20 ms
18,676 KB
testcase_13 AC 19 ms
18,712 KB
testcase_14 AC 18 ms
18,692 KB
testcase_15 AC 19 ms
18,692 KB
testcase_16 AC 19 ms
18,540 KB
testcase_17 AC 19 ms
18,644 KB
testcase_18 AC 19 ms
18,544 KB
testcase_19 AC 19 ms
18,696 KB
testcase_20 AC 19 ms
18,636 KB
testcase_21 AC 18 ms
18,636 KB
testcase_22 AC 23 ms
18,692 KB
testcase_23 AC 20 ms
18,624 KB
testcase_24 AC 19 ms
18,688 KB
testcase_25 AC 19 ms
18,608 KB
testcase_26 AC 19 ms
18,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

const int MOD = 998244353;
class mint {
    using int64 = long long;
private:
    int64 x;
public:
    mint(const int64 x1=0) { x = x1%MOD; };

    mint& operator++(int n) { x+=1; return *this; };
    mint& operator--(int n) { x-=1; return *this; };
    mint& operator=(int64 n) { x=n%MOD; return *this; };
    mint& operator--() {x-=1; return *this; };
    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; }
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
    mint inv() const { return pow(MOD-2);}
    friend ostream& operator<<(ostream &os, const mint a) noexcept { return os << a.x; }
    constexpr bool operator == (const mint& r) const noexcept { return this->x == r.x; }
    constexpr bool operator != (const mint& r) const noexcept { return this->x != r.x; }
    mint pow(long long t) const {
        if (!t) return mint(1);
        mint a = pow(t>>1);
        a*=a;
        if(t&1) a*= *this;
        return a;
    }
};

struct combination {
    vector<mint> fact, ifact;

    // コンストラクタ
    combination(int n):fact(n+1),ifact(n+1) {
        fact[0] = mint(1);
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*mint(i);
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*mint(i);
    }

    mint nCr(int n, int r) {
        if (r < 0 || r > n) return 0;
        return fact[n]*ifact[r]*ifact[n-r];
    }
    mint nPr(int n, int r) {
        if (r < 0 || r > n) return 0;
        return fact[n]*ifact[n-r];
    }
} comb(1000005);

int main() {
    int64 n,m;
    cin >> n >> m;
    if (n==1) {
        cout << 1 << endl;
        return 0;
    }

    mint ans = 1;
    for (int64 i=1; i<=m/n; i++) {
        int64 rest = m - i*n;
        ans += comb.nCr(rest + i, i);
    }

    cout << ans << endl;
}
0