結果

問題 No.2483 Yet Another Increasing XOR Problem
ユーザー kotatsugamekotatsugame
提出日時 2023-09-22 22:59:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 811 bytes
コンパイル時間 686 ms
コンパイル使用メモリ 67,840 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 22:59:58
合計ジャッジ時間 1,673 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cassert>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;
long M;
mint dp[66][2];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>M;
	int mb=0;
	while(M>>mb+1)mb++;
	long MX=(1LL<<mb+1)-1;
	mint ans=mint::raw(2).pow(MX+1)-1;
	ans-=mint::raw(2).pow(MX-M+1)-1;
	dp[mb+1][0]=mint::raw(1);
	for(int i=mb;i>=0;i--)
	{
		for(int j=0;j<2;j++)if(dp[i+1][j].val()!=0)
		{
			for(int a=0;a<2;a++)for(int b=0;b<2;b++)
			{
				if(j==0&&(a^b)<(M>>i&1))continue;
				if(i==mb&&a>b)continue;
				int nj=j;
				if((a^b)>(M>>i&1))nj=1;
				mint coef=mint::raw(1);
				if(a==1)coef*=mint::raw(2).pow(1L<<i);
				if(b==0)coef*=mint::raw(2).pow(1L<<i);
				dp[i][nj]+=dp[i+1][j]*coef;
			}
		}
	}
	ans-=dp[0][1]+dp[0][0];
	cout<<ans.val()<<endl;
}
0