結果

問題 No.2483 Yet Another Increasing XOR Problem
ユーザー pockynypockyny
提出日時 2023-10-03 07:52:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,142 bytes
コンパイル時間 1,104 ms
コンパイル使用メモリ 95,308 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-03 07:52:35
合計ジャッジ時間 2,360 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <atcoder/modint>
#include <map>

using namespace std;
using namespace atcoder;
using mint = modint998244353;
using ll = long long;
mint pw(mint a,ll x){
    if(x<0) a = 1/mint(a);
    x = abs(x);
    mint ret = 1;
    while(x){
        if(x&1) (ret *= a);
        x /= 2; a *= a;
    }
    return ret;
}

map<pair<ll,ll>,mint> mp;
ll mx = -10000;
mint solve(ll z,ll dig){
    if(z<0 || dig<0) return 0;
    if(dig==0) return 1;
    if(z==0) return mint(1LL<<dig);
    if(mp.find({z,dig})!=mp.end()) return mp[{z,dig}];
    mint inv = (mint)1/(mint)2;
    return mp[{z,dig}] = 2*solve(z/2,dig - 1) + (pw(2,1LL<<(mx - dig)) + pw(2,(1LL<<(mx - dig))*(-1)))*solve((z - 1)/2,dig - 1);
}

int main(){
    ll m; cin >> m;
    int d = 0;
    ll n = m;
    while(n){
        n /= 2; d++;
    }
    mint ans = pw(2,(1LL<<(d - 1)) - 1) - 1 + pw(2,1LL<<(d - 1)) - pw(2,(1LL<<d) - m);
    mx = d - 1;
    mint val = solve(m - (1LL<<(d - 1)) - 1,d - 1) - (pw(2,m - (1LL<<(d - 1))) - 1)/pw(2,m - (1LL<<(d - 1)) - 1);
    ans += pw(2,(1LL<<(d - 1)) - 2)*val;
    ans = 2*ans + 1;
    cout << ans.val() << "\n";
}
0