結果

問題 No.2653 [Cherry 6th Tune] Re: start! (Make it Zero!)
ユーザー kokoseikokosei
提出日時 2024-02-24 10:59:33
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,629 bytes
コンパイル時間 3,415 ms
コンパイル使用メモリ 248,272 KB
実行使用メモリ 7,392 KB
最終ジャッジ日時 2024-02-24 10:59:42
合計ジャッジ時間 9,558 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using ll = long long;
using mint = atcoder::modint998244353;

int N;
ll M;
int X[201010];
ll Sf[201010], Sb[201010];
mint mpow(mint a, ll b){
    if(b == 0)return 1;
    mint r = 1;
    while(b){
        if(b & 1)r = r * a;
        a = a * a;
        b >>= 1;
    }
    return r;
}
void solve(){
    cin >> N >> M;
    int c = 0;
    Sf[0] = Sb[N - 1] = 0;
    for(int i = 0;i < N;i++){
        cin >> X[i];
        c += (X[i] == -1);
    }
    for(int i = 0;i < N;i++){
        Sf[i] += X[i];
        Sf[i + 1] += Sf[i];
    }
    for(int i = N - 1;i > 0;i--){
        Sb[i - 1] = X[i] + Sb[i];
    }
    if(c == 0){
        int ans = N;
        for(int i = 0;i < N;i++){
            ans -= (Sf[i] % M) == 0;
        }
        cout << (Sf[N - 1] % M == 0 ? ans : 0) << "\n";
        return;
    }
    if(c == 1){
        ll s = 0;
        ll k = (M - (Sf[N - 1] + 1) % M) % M;
        int ans = N;
        for(int i = 0;i < N;i++){
            s += (X[i] == -1 ? k : X[i]);
            s %= M;
            ans -= (s == 0);
        }
        cout << ans << "\n";
        return;
    }
    mint ans = mpow(M, c - 1) * N;
    int nc = 0;
    for(int i = 0;i < N;i++){
        if(X[i] == -1){
            nc++;
            c--;
        }
        mint f = (nc == 0 ? Sf[i] % M == 0 : mpow(M, nc - 1));
        mint g = ( c == 0 ? Sb[i] % M == 0 : mpow(M,  c - 1));
        ans -= f * g;
    }
    cout << ans.val() << "\n";
}
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t; cin >> t;
    while(t--)solve();
    return 0;
}
0