結果

問題 No.2483 Yet Another Increasing XOR Problem
ユーザー milanis48663220milanis48663220
提出日時 2023-09-22 23:36:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,117 bytes
コンパイル時間 1,525 ms
コンパイル使用メモリ 122,424 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 23:36:46
合計ジャッジ時間 5,302 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int get_msb(ll)’ 内:
main.cpp:57:1: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
   57 | }
      | ^

ソースコード

diff #

#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;
}
0