結果
| 問題 |
No.2483 Yet Another Increasing XOR Problem
|
| コンテスト | |
| ユーザー |
aaaaa
|
| 提出日時 | 2023-10-03 07:50:06 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,969 bytes |
| コンパイル時間 | 708 ms |
| コンパイル使用メモリ | 80,836 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 01:53:33 |
| 合計ジャッジ時間 | 1,495 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 |
ソースコード
#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 x = solve(z/2,dig - 1);
mint y = solve((z - 1)/2,dig - 1);
mint inv = (mint)1/(mint)2;
// cout << x.val() << " xy " << y.val() << " " << mx - dig << endl;
// if(z==1 && dig==1){
// cout << "alpha " << mx - dig << " " << pw(2,1LL<<(mx - dig)).val() << " " << (pw(2,(1LL<<dig - mx)*(-1))*16).val() << endl;
// }
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 val1 = solve(m - (1LL<<(d - 1)) - 1,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);
// mint x = 0;
// for(int i=0;i<(1<<(d - 1));i++){
// for(int j=0;j<(1<<(d - 1));j++){
// if((i^j)<=m - (1<<(d - 1)) - 1) x += pw(2,i - j);
// }
// }
// cout << "x = " << (x*8).val() << endl;
// val = x;
// cout << m - (1LL<<(d - 1)) - 1 << " " << d - 1 << endl;
// for(auto p:mp){
// cout << "{" << p.first.first << "," << p.first.second << "," << (p.second*8).val() << "}" << endl;
// }
ans += pw(2,(1LL<<(d - 1)) - 2)*val;
ans = 2*ans + 1;
cout << ans.val() << "\n";
}
aaaaa