結果

問題 No.2653 [Cherry 6th Tune] Re: start! (Make it Zero!)
ユーザー 沙耶花沙耶花
提出日時 2024-02-23 22:53:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,106 bytes
コンパイル時間 4,622 ms
コンパイル使用メモリ 263,520 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-23 22:54:23
合計ジャッジ時間 12,875 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 38 ms
6,676 KB
testcase_02 AC 43 ms
6,676 KB
testcase_03 AC 43 ms
6,676 KB
testcase_04 AC 48 ms
6,676 KB
testcase_05 AC 47 ms
6,676 KB
testcase_06 AC 84 ms
6,676 KB
testcase_07 AC 85 ms
6,676 KB
testcase_08 AC 51 ms
6,676 KB
testcase_09 AC 50 ms
6,676 KB
testcase_10 AC 52 ms
6,676 KB
testcase_11 AC 47 ms
6,676 KB
testcase_12 AC 52 ms
6,676 KB
testcase_13 AC 32 ms
6,676 KB
testcase_14 AC 33 ms
6,676 KB
testcase_15 AC 33 ms
6,676 KB
testcase_16 AC 33 ms
6,676 KB
testcase_17 AC 33 ms
6,676 KB
testcase_18 AC 33 ms
6,676 KB
testcase_19 AC 33 ms
6,676 KB
testcase_20 AC 33 ms
6,676 KB
testcase_21 AC 33 ms
6,676 KB
testcase_22 AC 33 ms
6,676 KB
testcase_23 AC 33 ms
6,676 KB
testcase_24 AC 33 ms
6,676 KB
testcase_25 AC 34 ms
6,676 KB
testcase_26 AC 34 ms
6,676 KB
testcase_27 AC 35 ms
6,676 KB
testcase_28 AC 34 ms
6,676 KB
testcase_29 AC 33 ms
6,676 KB
testcase_30 AC 32 ms
6,676 KB
testcase_31 AC 34 ms
6,676 KB
testcase_32 AC 34 ms
6,676 KB
testcase_33 AC 31 ms
6,676 KB
testcase_34 AC 37 ms
6,676 KB
testcase_35 AC 36 ms
6,676 KB
testcase_36 AC 35 ms
6,676 KB
testcase_37 AC 38 ms
6,676 KB
testcase_38 AC 37 ms
6,676 KB
testcase_39 AC 35 ms
6,676 KB
testcase_40 AC 34 ms
6,676 KB
testcase_41 AC 36 ms
6,676 KB
testcase_42 AC 31 ms
6,676 KB
testcase_43 AC 82 ms
6,676 KB
testcase_44 AC 82 ms
6,676 KB
testcase_45 AC 82 ms
6,676 KB
testcase_46 AC 83 ms
6,676 KB
testcase_47 AC 83 ms
6,676 KB
testcase_48 AC 84 ms
6,676 KB
testcase_49 AC 82 ms
6,676 KB
testcase_50 AC 83 ms
6,676 KB
testcase_51 AC 83 ms
6,676 KB
testcase_52 AC 83 ms
6,676 KB
testcase_53 AC 32 ms
6,676 KB
testcase_54 AC 38 ms
6,676 KB
testcase_55 AC 35 ms
6,676 KB
testcase_56 AC 31 ms
6,676 KB
testcase_57 AC 35 ms
6,676 KB
testcase_58 AC 32 ms
6,676 KB
testcase_59 AC 35 ms
6,676 KB
testcase_60 AC 35 ms
6,676 KB
testcase_61 AC 44 ms
6,676 KB
testcase_62 AC 40 ms
6,676 KB
testcase_63 AC 27 ms
6,676 KB
testcase_64 AC 27 ms
6,676 KB
testcase_65 AC 27 ms
6,676 KB
testcase_66 AC 30 ms
6,676 KB
testcase_67 AC 30 ms
6,676 KB
testcase_68 AC 30 ms
6,676 KB
testcase_69 AC 31 ms
6,676 KB
testcase_70 AC 30 ms
6,676 KB
testcase_71 AC 31 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int _t;
	cin>>_t;
	
	rep(_,_t){
		int N,M;
		cin>>N>>M;
		vector<int> a(N);
		long long s = 0;
		long long f = 0;
		rep(i,N){
			cin>>a[i];
			if(a[i]==-1){
				f ++;
			}
			else{
				s += a[i];
			}
			
		}
		s %= M;
		mint ans = 0;
		if(f){
			mint t = mint(M).pow(f-1);
			ans = t;
		}
		else{
			if(s!=0){
				cout<<0<<endl;
				continue;
			}
			ans = 1;
			
		}
		ans *= N-1;
		
		long long sx = 0,sy = 0,fx = 0,fy = 0;
		sy = s,fy = f;
		rep(i,N-1){
			if(a[i]==-1){
				fx ++;
				fy --;
			}
			else{
				sx += a[i];
				sy -= a[i];
				sy += M;
				sx %= M;
				sy %= M;
			}
			mint t = 1;
			if(sx!=0&&fx==0)continue;
			if(sy!=0&&fy==0)continue;
			if(fx>0)t *= mint(M).pow(fx-1);
			if(fy>0)t *= mint(M).pow(fy-1);
			ans -= t;
		}
		
		cout<<ans.val()<<endl;
	}
	
	return 0;
}
0