結果

問題 No.2670 Sum of Products of Interval Lengths
ユーザー kotatsugamekotatsugame
提出日時 2024-03-08 23:35:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 772 bytes
コンパイル時間 6,764 ms
コンパイル使用メモリ 74,220 KB
実行使用メモリ 13,824 KB
最終ジャッジ日時 2024-03-08 23:36:10
合計ジャッジ時間 2,453 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 AC 51 ms
13,824 KB
testcase_02 AC 23 ms
8,448 KB
testcase_03 AC 9 ms
6,676 KB
testcase_04 AC 23 ms
8,448 KB
testcase_05 AC 36 ms
10,880 KB
testcase_06 AC 43 ms
12,032 KB
testcase_07 AC 29 ms
8,448 KB
testcase_08 AC 11 ms
6,676 KB
testcase_09 AC 32 ms
8,448 KB
testcase_10 AC 48 ms
10,880 KB
testcase_11 AC 56 ms
12,032 KB
testcase_12 AC 52 ms
13,824 KB
testcase_13 AC 51 ms
13,824 KB
testcase_14 AC 51 ms
13,824 KB
testcase_15 AC 52 ms
13,824 KB
testcase_16 AC 51 ms
13,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cassert>
#include<atcoder/modint>
#include<atcoder/fenwicktree>
using namespace std;
using mint=atcoder::modint998244353;
int N;
long M;
mint dp[2<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>M;
	atcoder::fenwick_tree<mint>BIT[6][2];
	for(int i=0;i<6;i++)for(int j=0;j<2;j++)
	{
		BIT[i][j]=atcoder::fenwick_tree<mint>(N+1);
	}
	dp[0]=1;
	auto st=[&](int i){
		BIT[i%6][0].add(i,dp[i]);
		BIT[i%6][1].add(i,dp[i]*i);
	};
	st(0);
	for(int i=1;i<=N;i++)
	{
		dp[i]=0;
		int li=max(0L,i-M);
		for(int v=0;v<6&&v<=i;v++)if(v%3!=0)
		{
			int j=(i-v)%6;
			mint t0=BIT[j][0].sum(li,i);
			mint t1=BIT[j][1].sum(li,i);
			mint t=(M-i+1)*t0+t1;
			if(v>=3)t=-t;
			dp[i]+=t;
		}
		st(i);
	}
	cout<<dp[N].val()<<endl;
}
0