結果

問題 No.2206 Popcount Sum 2
ユーザー Ricky_ponRicky_pon
提出日時 2023-02-04 00:30:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,078 ms / 4,000 ms
コード長 3,953 bytes
コンパイル時間 1,634 ms
コンパイル使用メモリ 141,612 KB
実行使用メモリ 62,080 KB
最終ジャッジ日時 2023-09-15 20:50:59
合計ジャッジ時間 19,392 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
62,080 KB
testcase_01 AC 105 ms
61,864 KB
testcase_02 AC 111 ms
61,728 KB
testcase_03 AC 111 ms
61,832 KB
testcase_04 AC 111 ms
61,800 KB
testcase_05 AC 1,078 ms
62,008 KB
testcase_06 AC 1,077 ms
61,836 KB
testcase_07 AC 1,077 ms
61,800 KB
testcase_08 AC 1,077 ms
61,948 KB
testcase_09 AC 1,078 ms
61,740 KB
testcase_10 AC 1,047 ms
61,952 KB
testcase_11 AC 1,044 ms
61,736 KB
testcase_12 AC 1,045 ms
61,836 KB
testcase_13 AC 1,017 ms
61,796 KB
testcase_14 AC 1,021 ms
61,852 KB
testcase_15 AC 1,019 ms
61,864 KB
testcase_16 AC 1,031 ms
61,840 KB
testcase_17 AC 1,035 ms
61,868 KB
testcase_18 AC 1,027 ms
61,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #include <bits/stdc++.h>
#include <string.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <ciso646>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define For(i, a, b) for (int i = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For(i, 0, n)
#define rrep(i, n) rFor(i, n, 0)
#define fi first
#define se second

#include <atcoder/modint>

#include <atcoder/modint>
#include <vector>

namespace rklib {

template <class T>
struct Factorial {
   public:
    Factorial() : Factorial(0) {}
    Factorial(int n) {
        fc.resize(n + 1);
        inv_fc.resize(n + 1);
        fc[0] = 1;
        for (int i = 0; i < n; ++i) fc[i + 1] = fc[i] * (i + 1);

        inv_fc[n] = 1 / fc[n];
        for (int i = n - 1; i >= 0; --i) inv_fc[i] = inv_fc[i + 1] * (i + 1);
    }

    T fact(int n) {
        if (n >= (int)fc.size()) extend(n);
        return fc[n];
    }

    T inv_fact(int n) {
        if (n >= (int)fc.size()) extend(n);
        return inv_fc[n];
    }

    T inv(int n) {
        assert(n > 0);
        if (n >= (int)fc.size()) extend(n);
        return inv_fc[n] * fc[n - 1];
    }

    T comb(int n, int r) {
        if (n < r || r < 0) return 0;
        if (n >= (int)fc.size()) extend(n);
        return fc[n] * inv_fc[r] * inv_fc[n - r];
    }

    T perm(int n, int r) {
        if (n < r || r < 0) return 0;
        if (n >= (int)fc.size()) extend(n);
        return fc[n] * inv_fc[n - r];
    }

   private:
    std::vector<T> fc;
    std::vector<T> inv_fc;

    void extend(int n) {
        int l = fc.size();
        int r = l;
        while (r <= n) r *= 2;

        fc.resize(r);
        inv_fc.resize(r);

        for (int i = l; i < r; ++i) fc[i] = fc[i - 1] * i;

        inv_fc[r - 1] = 1 / fc[r - 1];
        for (int i = r - 2; i >= l; --i) inv_fc[i] = inv_fc[i + 1] * (i + 1);
    }
};

}  // namespace rklib


#include <algorithm>
#include <cassert>
#include <vector>

namespace rklib {

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

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

template <class T>
bool chmin_non_negative(T &a, const T &b) {
    if (a < 0 || a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}

template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

}  // namespace rklib


using namespace std;
using namespace rklib;

using lint = long long;
using pii = pair<int, int>;
using pll = pair<lint, lint>;

using mint = atcoder::modint998244353;

constexpr int MAX = 200005;
constexpr int W = 1500;

vector<vector<mint>> table(MAX);

int main() {
    int t;
    scanf("%d", &t);
    Factorial<mint> fc(MAX);

    rep(i, MAX) {
        if (i % W != 0) continue;
        table[i].resize(i + 1, 1);
        For(j, 1, i + 1) table[i][j] = table[i][j - 1] + fc.comb(i, j);
    }
    auto f = [&](int n, int m) {
        int a = n / W * W;
        int b = min(m, a);
        mint res = table[a][b];
        For(i, a, n) res = res * 2 - fc.comb(i, b);
        For(j, b + 1, m + 1) res += fc.comb(n, j);
        return res;
    };

    rep(tt, t) {
        int n, m;
        scanf("%d%d", &n, &m);

        mint ans = f(n - 1, m - 1);
        ans *= (mint(2).pow(n) - 1);
        printf("%u\n", ans.val());
    }
}
0