結果

問題 No.1952 xooooooooooor
ユーザー RVindicatioRVindicatio
提出日時 2022-05-20 23:30:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 3,123 bytes
コンパイル時間 3,269 ms
コンパイル使用メモリ 229,296 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 14:28:03
合計ジャッジ時間 4,825 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 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 1 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 1 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 1 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 1 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
const int INF = 1e9;
const ll inf = 1LL<<60;

template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<998244353> mint;

void solve() {
  int n, m; cin >> n >> m;
  string l = "";
  while (n > 0) {
    if (n & 1) l += '1';
    else l += '0';
    n /= 2;
  }
  reverse(l.begin(), l.end());
  if (m < 100) {
    vector<string> t(m);
    t[0] = l;
    for (int i=1; i<m; i++) {
      t[i] = t[i-1] + '0';
    }
    for (int i=0; i<m; i++) {
      reverse(t[i].begin(), t[i].end());
      while (t[i].size() < t.back().size()) t[i] += '0';
    }
    mint ans = mint(0);
    for (int i=0; i<t[0].size(); i++) {
      int p = 0;
      for (int j=0; j<m; j++) p ^= (t[j][i] == '1' ? 1 : 0);
      if (p) ans += mint(2)^(i);
    }
    cout << ans << '\n';
  } else {
    reverse(l.begin(), l.end());
    int L = l.size();
    mint ans = mint(0);
    int p = 0;
    for (int i=0; i+1<L; i++) {
      p ^= (l[i] == '1' ? 1 : 0);
      if (p) ans += mint(2)^(i);
    }
    p ^= (l.back() == '1' ? 1 : 0);
    if (p) {
      mint e = mint(2)^(L-1);
      e *= ((mint(2)^(m-L+1)) - mint(1));
      ans += e;
    }
    mint q = mint(2)^(m);
    for (int i=0; i<L-1; i++) {
      p ^= (l[i] == '1' ? 1 : 0);
      if (p) ans += q;
      q *= mint(2);
    }
    cout << ans << '\n';
  }
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  // int t; cin >> t;
  /*while (t--)*/ solve();
}
0