結果

問題 No.2483 Yet Another Increasing XOR Problem
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2023-09-23 08:19:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,260 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 199,984 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-23 08:19:12
合計ジャッジ時間 3,213 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll const m = 998244353;
ll mpow(ll a, ll n) {
	n %= (m - 1);
	ll ret = 1;
	while (n) {
		if (n & 1) ret = (ret * a) % m;
		a = (a * a) % m;
		n >>= 1;
	}
	return ret;
}
int main() {
	ll N;
	cin >> N;
	if (N < 3) {
		if (N == 1) {
			puts("1");
		}
		if (N == 2) {
			puts("3");
		}
		return 0;
	}
	N --;
	ll n = 1; int lg = -1;
	while (n <= N) {
		n <<= 1;
		lg ++;
	}
	n >>= 1;
	ll ans = mpow(2, n) - 1;
	ll dp[60][3];
	if (N & 1) {
		dp[0][1] = 2 + (m + 1) / 2; dp[0][0] = 2; dp[0][2] = 0;
	} else {
		dp[0][0] = 0; dp[0][1] = 2;dp[0][2] = 2 + (m + 1) / 2;
	}
	for (int i = 1; i < lg; i ++) {
		ll* pre = dp[i - 1];
		ll* now = dp[i];
		ll b = mpow(2, (1ll << i));
		ll iv = mpow(b, m - 2);
		if ((N >> i) & 1) {
			now[0] = (pre[0] + pre[1] + pre[2]) * 2; now[0] %= m;
			now[1] = 0; now[2] = 0;
			for (int j = 0; j < 3; j ++) {
				now[j] += pre[j] * (b + iv) % m;
				now[j] %= m;
			}
		} else {
			for (int j = 0; j < 3; j ++) {
				now[j] = pre[j] * 2;
				now[j] %= m;
			}
			now[2] += (pre[0] + pre[1] + pre[2]) * ((b + iv) % m);
			now[2] %= m;
		}
	}
	ll kj = dp[lg - 1][0] + dp[lg - 1][1];
	kj %= m;
	kj = (kj * mpow(2, (1ll << lg) - 1)) % m;
	cout << (ans + kj) % m << endl;
}
0