結果

問題 No.3431 popcount & sum (Easy)
コンテスト
ユーザー Nzt3
提出日時 2026-02-28 04:25:34
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,985 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,191 ms
コンパイル使用メモリ 343,216 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-02-28 04:25:40
合計ジャッジ時間 4,703 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/vector:67,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/functional:66,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:55,
                 from main.cpp:2:
In function '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = atcoder::static_modint<998244353>*; _ForwardIterator = atcoder::static_modint<998244353>*]',
    inlined from 'constexpr _ForwardIterator std::__uninitialized_copy_a(_InputIterator, _Sentinel, _ForwardIterator, allocator<_Tp>&) [with _InputIterator = atcoder::static_modint<998244353>*; _Sentinel = atcoder::static_modint<998244353>*; _ForwardIterator = atcoder::static_modint<998244353>*; _Tp = atcoder::static_modint<998244353>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_uninitialized.h:635:32,
    inlined from 'constexpr std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = atcoder::static_modint<998244353>; _Alloc = std::allocator<atcoder::static_modint<998244353> >]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/vector.tcc:257:35,
    inlined from 'int main()' at main.cpp:63:13:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_uninitialized.h:273:31: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' writing between 1 and 244 bytes into a region of size 0 overflows the destination [-Wstringop-overflow=]
  273 |               __builtin_memcpy(std::__niter_base(__result),
      |               ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  274 |                                std::__niter_base(__first),
      |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  275 |                                __n * sizeof(_ValT));
      |            

ソースコード

diff #
raw source code

#include <atcoder/modint.hpp>
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep3(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define rep2(i, a, b) rep3(i, a, b, 1)
#define rep1(i, n) rep2(i, 0, n)
#define rep0(n) rep1(aaaaa, n)
#define ov4(a, b, c, d, name, ...) name
#define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)
#define per(i, a, b) for (ll i = (a) - 1; i >= (b); i--)
#define fore(e, v) for (auto &&e : v)
#define all(a) begin(a), end(a)
#define sz(a) (int)(size(a))
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define eb emplace_back

template <typename T, typename S> bool chmin(T &a, const S &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename S> bool chmax(T &a, const S &b) {
  return a < b ? a = b, 1 : 0;
}
const int INF = 1e9 + 100;
const ll INFL = 3e18 + 100;
#define i128 __int128_t
struct _ {
  _() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); }
} __;

using mint = atcoder::modint998244353;

int main() {
  ll N;
  cin >> N;
  const int D = 61;
  mint ans = 0;
  rep(b, D) {
    vector dp0(D, mint(0)), dp1(D, mint(0));
    dp0[0] = 1;
    per(i, D, 0) {
      vector ndp0(D, mint(0)), ndp1(D, mint(0));
      if (i == b) {
        if (N >> i & 1) {
          rep(p, D - 1) ndp0[p + 1] += dp0[p], ndp1[p + 1] += dp1[p];
        } else {
          rep(p, D - 1) ndp1[p + 1] += dp1[p];
        }
      } else {
        if (N >> i & 1) {
          rep(p, D - 1) ndp0[p + 1] += dp0[p], ndp1[p + 1] += dp1[p];
          rep(p, D) ndp1[p] += dp0[p] + dp1[p];
        } else {
          rep(p, D - 1) ndp1[p + 1] += dp1[p];
          rep(p, D) ndp0[p] += dp0[p], ndp1[p] += dp1[p];
        }
      }
      dp0 = ndp0, dp1 = ndp1;
    }
    mint c = mint(2).pow(b);
    rep(i, D) {
      mint v = dp0[i] + dp1[i];
      ans += c * v * (v + 1) / 2;
    }
  }
  cout << ans.val() << '\n';
}
0