結果
問題 | No.1531 く2 |
ユーザー |
![]() |
提出日時 | 2023-07-19 00:49:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 12 ms / 2,000 ms |
コード長 | 2,435 bytes |
コンパイル時間 | 1,218 ms |
コンパイル使用メモリ | 121,988 KB |
最終ジャッジ日時 | 2025-02-15 15:41:31 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 44 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #include <atcoder/modint> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using mint = atcoder::modint998244353; ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } mint naive(ll n, ll k){ mint ans = 0; for(ll y = 0; y <= n; y++){ if((y&n) == y){ ll t = y+k; int c = __builtin_popcountll(t); ans += 1ll<<c; } } return ans; } mint solve(ll n, ll k){ auto dp = vec3d(64, 64, 2, mint(0)); dp[0][0][0] = 1; for(int i = 0; i <= 62; i++){ int nx = (n&(1ll<<i)) ? 1 : 0; int kx = (k&(1ll<<i)) ? 1 : 0; for(int p = 0; p <= i; p++){ for(int carry = 0; carry < 2; carry++){ for(int x = 0; x <= nx; x++){ int carry_next = (kx+x+carry)/2; int current_bit = (kx+x+carry)%2; dp[i+1][p+current_bit][carry_next] += dp[i][p][carry]; } } } } mint ans = 0; for(int p = 0; p <= 63; p++){ ans += dp[63][p][0]*(1ll<<p); } return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; ll n, k; cin >> n >> k; // cout << naive(n, k) << endl; cout << solve(n, k) << endl; }