結果

問題 No.1952 xooooooooooor
ユーザー MazesobaMazesoba
提出日時 2022-05-26 08:17:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,108 bytes
コンパイル時間 4,432 ms
コンパイル使用メモリ 263,820 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 19:21:25
合計ジャッジ時間 5,930 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;

//#define DISABLE_PRINT

#if defined(ENABLE_PRINT) && !defined(DISABLE_PRINT)

#define P(...) fprintf(stderr, __VA_ARGS__)
#define P2(fmt) fprintf(stderr, fmt)
#define LP fprintf(stderr, "L: %d\n", __LINE__)

#else

#define P(...) ((void)0)
#define P2(fmt) ((void)0)
#define LP ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define ALL(x) x.begin(),x.end()

using ll = long long;
using ull = unsigned long long;

using mint = atcoder::modint998244353;

int main(int, const char**)
{
    ull N, M; cin >> N >> M;
    if(N == 0) {
        cout << 0 << endl;
        return 0;
    }
    auto f = [&](ull x) {
        vector<int> ds;
        while(x != 0) {
            ds.push_back(x % 2);
            x /= 2;
        }
        return ds;
    };
    
    auto ds = f(N);
    if(M <= ds.size()) {
        assert(M <= 32);
        ull ans = 0;
        auto x = N;
        rep(i, M) {
            ans ^= x;
            x <<= 1;
        }
        cout << mint(ans).val() << endl;
        return 0;
    }

    auto len = (int)ds.size();
    mint ans = 0;
    mint base = 1;
    int v = 0;
    rep(i, len - 1) {
        v ^= ds[i];
        ans += base * v;
        base *= 2;
        P("%d", v);
    }
    P("\n");

    auto mlen = M - len + 1;
    v ^= ds.back();
    if(v == 1) {
        auto tb = mint(2).pow(mlen) - 1;
        tb *= base;
        ans += tb;
        P("tb: %d\n", tb);
    }
    P("ans: %ld\n", ans.val());

    vector<int> tops;
    v = 0;
    rep(i, len - 1) {
        v ^= ds[len - 1 - i];
        P("%d, \n", v);
        tops.push_back(v);
    }
    P("\n");

    base = mint(2).pow(mlen + len - 1);
    P("base: %d\n", base.val());
    rep(i, len - 1) {
        auto tv = tops[len - 2 - i];
        P("tv: %d\n", tv);
        ans += base * tv;
        base *= 2;
    }

    cout << ans.val() << endl;

    vector<int> av;
    auto x = ans.val();
    while(x != 0) {
        av.push_back(x % 2);
        x /= 2;
    }
    for(auto a : av) {
        P("%d", a);
    }
    P("\n");

    return 0;
}
0