結果

問題 No.2144 MM
ユーザー 沙耶花沙耶花
提出日時 2022-12-02 22:32:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 1,513 bytes
コンパイル時間 4,970 ms
コンパイル使用メモリ 254,808 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 07:08:21
合計ジャッジ時間 7,912 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 68 ms
5,376 KB
testcase_08 AC 111 ms
5,376 KB
testcase_09 AC 66 ms
5,376 KB
testcase_10 AC 111 ms
5,376 KB
testcase_11 AC 110 ms
5,376 KB
testcase_12 AC 110 ms
5,376 KB
testcase_13 AC 104 ms
5,376 KB
testcase_14 AC 109 ms
5,376 KB
testcase_15 AC 90 ms
5,376 KB
testcase_16 AC 26 ms
5,376 KB
testcase_17 AC 80 ms
5,376 KB
testcase_18 AC 21 ms
5,376 KB
testcase_19 AC 84 ms
5,376 KB
testcase_20 AC 76 ms
5,376 KB
testcase_21 AC 55 ms
5,376 KB
testcase_22 AC 13 ms
5,376 KB
testcase_23 AC 79 ms
5,376 KB
testcase_24 AC 22 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
int n,m;
vector<int> c;

void dfs(int cur,int cv){
	if(cur==n){
		c[cv] ++;
		return;
	}
	rep(i,m-1){
		if(cur%2==0){
			dfs(cur+1,(cv+i)%m);
		}
		else{
			dfs(cur+1,(cv-i+m)%m);
		}
	}
}

bool check(int l,int r){
	if(l<=r){
		if(l<=1&&1<=r)return true;
	}
	else{
		if(r>=1)return true;
	}
	return false;
}


int main(){
	
	
	cin>>n>>m;
	/*
	c.resize(m,0);
	dfs(0,0);
	
	rep(i,m){
		cout<<c[i]<<endl;
	}
	*/
	
	vector<int> a(n);
	int s= 0 ;
	rep(i,n){
		cin>>a[i];
		if(i%2==0){
			s += a[i];
		}
		else{
			s += m-a[i];
		}
		s %= m;
	}
	if(s!=0){
		cout<<-1<<endl;
		return 0;
	}
	
	
	mint ans = 1;
	
	s = 0;
	
	rep(i,n){
		if(a[i]!=0){
			int l,r;
			if(i%2==0){
				l = s;
				r = s+a[i]-1;
				r %= m;
			}
			else{
				r = s;
				l = s - (a[i]-1) + m;
				l %= m;
			}
			//cout<<l<<','<<r<<endl;
			int remain = n-1-i;
			if(remain%2==0){
				mint t = mint(m-1).pow(remain)-1;
				t /= m;
				ans += t * a[i];
				
				if(l==0||l>r)ans++;
				//if(check(l,r))ans++;
			}
			else{
				mint t = mint(m-1).pow(remain)+1;
				t /= m;
				ans += t * a[i];
				if(n%2==1&&check(l,r))ans--;
				if(n%2==0&&(r==m-1 || l>r))ans--;
			}
		}
		
		if(i%2==0){
			s += a[i];
		}
		else{
			s += m-a[i];
		}
		s %= m;
	}
	//ans++;
	cout<<ans.val()<<endl;
	
	return 0;
}
0