結果

問題 No.1952 xooooooooooor
ユーザー RVindicatio
提出日時 2022-05-20 23:30:23
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,123 bytes
コンパイル時間 11,589 ms
コンパイル使用メモリ 286,764 KB
最終ジャッジ日時 2025-01-29 11:51:26
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

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();
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0