結果
問題 |
No.2060 AND Sequence
|
ユーザー |
![]() |
提出日時 | 2025-03-29 07:51:48 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,396 bytes |
コンパイル時間 | 3,562 ms |
コンパイル使用メモリ | 276,900 KB |
実行使用メモリ | 7,324 KB |
最終ジャッジ日時 | 2025-03-29 07:51:53 |
合計ジャッジ時間 | 5,729 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 WA * 1 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/modint> using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); /* A_Nを固定する。 k=N, N-1, ..., 1と見ていった時、0->1となっていてはいけない。 つまり、A_Nのpopcountをkとすると、 A_0=0, A_1, ..., A_N-1のN箇所のどこかでそのbitが1になる。 よって、(M以下でpopcountがkになるもの)*N^kの和が答え。 bit DPでやる。 */ int N, M; cin >> N >> M; int popsame=0; vector<mint> dp(30); for (int i=29; i>=0; i--){ int c = (M>>i) & 1; popsame += c; vector<mint> pd(30); if (c){ //same->small pd[popsame-1] += 1; //small->small for (int j=0; j<=29; j++){ pd[j] += dp[j]; if (j) pd[j] += dp[j-1]; } } else{ //small->small for (int j=0; j<=29; j++){ pd[j] += dp[j]; if (j) pd[j] += dp[j-1]; } } swap(dp, pd); } dp[popsame]++; mint ans=0, pw=1; for (int i=0; i<=29; i++){ ans += dp[i] * pw; pw *= N; } cout << ans.val() << endl; return 0; }