結果

問題 No.2144 MM
ユーザー kotatsugamekotatsugame
提出日時 2022-12-02 22:13:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,638 bytes
コンパイル時間 1,120 ms
コンパイル使用メモリ 86,772 KB
実行使用メモリ 38,912 KB
最終ジャッジ日時 2024-04-18 06:31:58
合計ジャッジ時間 8,251 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 28 ms
34,432 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 67 ms
6,656 KB
testcase_08 WA -
testcase_09 AC 68 ms
6,656 KB
testcase_10 AC 577 ms
38,272 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 21 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 340 ms
21,248 KB
testcase_21 AC 293 ms
36,608 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 28 ms
34,432 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 16 ms
19,072 KB
testcase_28 WA -
testcase_29 AC 9 ms
11,136 KB
testcase_30 AC 31 ms
34,944 KB
testcase_31 WA -
testcase_32 AC 16 ms
17,664 KB
testcase_33 AC 5 ms
7,296 KB
testcase_34 AC 26 ms
32,256 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:16:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   16 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<atcoder/modint>
#include<atcoder/lazysegtree>
using namespace std;
using mint=atcoder::modint998244353;
using dat=pair<mint,mint>;//(val, len)
dat op(dat a,dat b){return make_pair(a.first+b.first,a.second+b.second);}
dat e(){return make_pair(mint::raw(0),mint::raw(0));}
using F=pair<mint,mint>;//(mul, add)
dat mp(F f,dat x){return make_pair(x.first*f.first+x.second*f.second,x.second);}
F cmp(F f,F g){return make_pair(g.first*f.first,g.second*f.first+f.second);}
F id(){return make_pair(mint::raw(1),mint::raw(0));}
int N,M;
int A[2<<17],sign[2<<17];
long S[2<<17];
main()
{
	cin>>N>>M;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		sign[i]=(N-i)%2==1?-1:1;
		S[i+1]=S[i]+A[i]*sign[i];
	}
	if(S[N]%M!=0)
	{
		cout<<-1<<endl;
		return 0;
	}
	atcoder::lazy_segtree<dat,op,e,F,mp,cmp,id>seg(vector<dat>(M,make_pair(mint::raw(0),mint::raw(1))));
	seg.set(0,make_pair(mint::raw(1),mint::raw(1)));
	int off=0;
	mint ans=1;
	for(int i=N-1;i>=0;i--)
	{
		if(sign[i]==1)
		{
			//0<=a<A[i], seg[S[i]+a-off]
			//S[i]-off<=*<S[i]+A[i]-off
			int L=((S[i]-off)%M+M)%M;
			int R=((S[i]+A[i]-off)%M+M)%M;
			if(L<=R)ans+=seg.prod(L,R).first;
			else ans+=seg.prod(L,M).first+seg.prod(0,R).first;
		}
		else
		{
			//0<=a<A[i], seg[S[i]-a-off]
			//S[i]-A[i]-off<*<=S[i]-off
			//S[i]-A[i]-off+1<=*<S[i]-off+1
			int L=((S[i]-A[i]-off+1)%M+M)%M;
			int R=((S[i]-off+1)%M+M)%M;
			if(L<=R)ans+=seg.prod(L,R).first;
			else ans+=seg.prod(L,M).first+seg.prod(0,R).first;
		}
		mint s=seg.all_prod().first;
		seg.apply(0,M,make_pair(mint(-1),s));
		if(sign[i]==1)off=(off-1+M)%M;
		else off=(off+1)%M;
	}
	cout<<ans.val()<<endl;
}
0