結果
| 問題 |
No.2206 Popcount Sum 2
|
| コンテスト | |
| ユーザー |
Ricky_pon
|
| 提出日時 | 2023-02-04 00:30:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,132 ms / 4,000 ms |
| コード長 | 3,953 bytes |
| コンパイル時間 | 3,413 ms |
| コンパイル使用メモリ | 136,792 KB |
| 最終ジャッジ日時 | 2025-02-10 10:21:06 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:171:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
171 | scanf("%d", &t);
| ~~~~~^~~~~~~~~~
main.cpp:190:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
190 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
// #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());
}
}
Ricky_pon