結果
問題 | No.2483 Yet Another Increasing XOR Problem |
ユーザー |
![]() |
提出日時 | 2023-09-22 23:36:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,117 bytes |
コンパイル時間 | 1,229 ms |
コンパイル使用メモリ | 121,320 KB |
最終ジャッジ日時 | 2025-02-17 01:10:03 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 TLE * 1 -- * 2 |
コンパイルメッセージ
main.cpp: In function ‘int get_msb(ll)’: main.cpp:57:1: warning: control reaches end of non-void function [-Wreturn-type] 57 | } | ^
ソースコード
#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; } int get_msb(ll m){ for(int i = 60; i >= 0; i--){ if(m&(1ll<<i)) return i; } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; ll m; cin >> m; m--; int msb = get_msb(m); auto dp = vec2d(msb+1, 2, mint(0)); dp[msb][1] = 1; for(int i = msb-1; i >= 0; i--){ int cur_bit = m&(1ll<<i) ? 1 : 0; for(int same = 0; same <= 1; same++){ for(int x = 0; x <= 1; x++){ for(int y = 0; y <= 1; y++){ int z = x^y; if(same == 1 && z > cur_bit) continue; int same_next = [&](){ if(same == 0) return 0; if(z < cur_bit) return 0; return 1; }(); // cout << same << ' ' << x << ' ' << y << ' ' << same_next << ' ' << dp[i+1][same] << endl; ll r = ((1ll<<i)*(x-y)) % (mint::mod()-1); r += (mint::mod()-1); r %= (mint::mod()-1); dp[i][same_next] += dp[i+1][same]*mint(2).pow(r); // dp[i][same_next] += dp[i+1][same]; } } } } ll r = (1ll<<(msb)) % (mint::mod()-1); r -= 1; r += (mint::mod()-1); r %= (mint::mod()-1); mint ans = (dp[0][0]+dp[0][1])*mint(2).pow(r); { // msbが立ってないのだけ or 立ってるのだけ ll r = (1ll<<(msb)) % (mint::mod()-1); r += (mint::mod()-1); r %= (mint::mod()-1); ans += (mint(2).pow(r)-1)*2; ll rr = (1ll<<(msb+1)) - m - 1; rr += (mint::mod()-1); rr %= (mint::mod()-1); ans -= mint(2).pow(rr)-1; } cout << ans << endl; }