結果

問題 No.2653 [Cherry 6th Tune] Re: start! (Make it Zero!)
ユーザー MagentorMagentor
提出日時 2024-02-23 21:44:59
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 2,713 bytes
コンパイル時間 5,332 ms
コンパイル使用メモリ 310,904 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-23 21:45:15
合計ジャッジ時間 16,031 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 85 ms
6,676 KB
testcase_02 AC 91 ms
6,676 KB
testcase_03 AC 93 ms
6,676 KB
testcase_04 AC 93 ms
6,676 KB
testcase_05 AC 93 ms
6,676 KB
testcase_06 AC 147 ms
6,676 KB
testcase_07 AC 148 ms
6,676 KB
testcase_08 AC 96 ms
6,676 KB
testcase_09 AC 101 ms
6,676 KB
testcase_10 AC 102 ms
6,676 KB
testcase_11 AC 109 ms
6,676 KB
testcase_12 AC 105 ms
6,676 KB
testcase_13 AC 76 ms
6,676 KB
testcase_14 AC 76 ms
6,676 KB
testcase_15 AC 76 ms
6,676 KB
testcase_16 AC 76 ms
6,676 KB
testcase_17 AC 76 ms
6,676 KB
testcase_18 AC 75 ms
6,676 KB
testcase_19 AC 77 ms
6,676 KB
testcase_20 AC 75 ms
6,676 KB
testcase_21 AC 79 ms
6,676 KB
testcase_22 AC 75 ms
6,676 KB
testcase_23 AC 79 ms
6,676 KB
testcase_24 AC 73 ms
6,676 KB
testcase_25 AC 78 ms
6,676 KB
testcase_26 AC 78 ms
6,676 KB
testcase_27 AC 82 ms
6,676 KB
testcase_28 AC 81 ms
6,676 KB
testcase_29 AC 79 ms
6,676 KB
testcase_30 AC 76 ms
6,676 KB
testcase_31 AC 79 ms
6,676 KB
testcase_32 AC 80 ms
6,676 KB
testcase_33 AC 81 ms
6,676 KB
testcase_34 AC 86 ms
6,676 KB
testcase_35 AC 83 ms
6,676 KB
testcase_36 AC 77 ms
6,676 KB
testcase_37 AC 88 ms
6,676 KB
testcase_38 AC 85 ms
6,676 KB
testcase_39 AC 77 ms
6,676 KB
testcase_40 AC 84 ms
6,676 KB
testcase_41 AC 77 ms
6,676 KB
testcase_42 AC 74 ms
6,676 KB
testcase_43 AC 135 ms
6,676 KB
testcase_44 AC 136 ms
6,676 KB
testcase_45 AC 137 ms
6,676 KB
testcase_46 AC 136 ms
6,676 KB
testcase_47 AC 136 ms
6,676 KB
testcase_48 AC 135 ms
6,676 KB
testcase_49 AC 136 ms
6,676 KB
testcase_50 AC 135 ms
6,676 KB
testcase_51 AC 136 ms
6,676 KB
testcase_52 AC 136 ms
6,676 KB
testcase_53 AC 69 ms
6,676 KB
testcase_54 AC 80 ms
6,676 KB
testcase_55 AC 100 ms
6,676 KB
testcase_56 AC 64 ms
6,676 KB
testcase_57 AC 76 ms
6,676 KB
testcase_58 AC 83 ms
6,676 KB
testcase_59 AC 93 ms
6,676 KB
testcase_60 AC 72 ms
6,676 KB
testcase_61 AC 85 ms
6,676 KB
testcase_62 AC 88 ms
6,676 KB
testcase_63 AC 72 ms
6,676 KB
testcase_64 AC 71 ms
6,676 KB
testcase_65 AC 80 ms
6,676 KB
testcase_66 AC 69 ms
6,676 KB
testcase_67 AC 70 ms
6,676 KB
testcase_68 AC 70 ms
6,676 KB
testcase_69 AC 71 ms
6,676 KB
testcase_70 AC 71 ms
6,676 KB
testcase_71 AC 71 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, m ,n) for (int i = (m); i < (long long)(n); i++)
#define REP(i, n) for (long long i = 1; i < (long long)(n); i++)
typedef long long ll;
#define updiv(N,X) (N + X - 1) / X
#define l(n) n.begin(),n.end()
#define YesNo(Q) Q==1?cout<<"Yes":cout<<"No"
using P = pair<int, int>;
using mint = modint;
const int MOD = 998244353LL;
const ll INF = 999999999999LL;
vector<long long> fact, fact_inv, inv;
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
template <typename T>
void input(vector<T> &v){
 rep(i,v.size()){cin>>v[i];}
  return;
}
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll POW(ll a,ll n){
  long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}
int main() {
 int t;cin>>t;
 while(t--){
 	ll n;cin>>n;
 	ll m;cin>>m;vector<ll> v(n);rep(i,n){cin>>v[i];}
 	ll cnt = 0;ll cnt2 = 0;mint ans = 0;
    ll cnt3 = 0;ll cnt4 = 0;
    rep(i,n){if(v[i]==-1){cnt3++;}else{cnt4 += v[i];}}
    rep(i,n){
    if(v[i]==-1){cnt3--;}else{cnt4 -= v[i];}
    if(v[i]==-1){cnt++;}else{cnt2 += v[i];}
    mint res = 1;
    if(cnt==0){if(cnt2%m!=0){res *= 0;}}
    else{res *= modpow(m,cnt-1,998244353LL);}
    if(cnt3==0){if(cnt4%m!=0){res *= 0;}}
    else{res *= modpow(m,cnt3-1,998244353LL);}
    ans += res;
    }
    mint res5 = 0;
  //  cout << ans.val() << endl;
    if(cnt==0){
    	if(cnt2%m==0){res5 = n;}
    	else{cout << 0 << endl;continue;}
    }
    else{
    	res5 = n*modpow(m,cnt-1,998244353LL);
    }
    cout << (res5-ans).val() << endl;
 }
}
0