結果

問題 No.2636 No Waiting in Vain
ユーザー GOTKAKOGOTKAKO
提出日時 2024-02-19 20:50:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 2,474 bytes
コンパイル時間 2,219 ms
コンパイル使用メモリ 204,980 KB
実行使用メモリ 10,716 KB
最終ジャッジ日時 2024-02-19 20:50:22
合計ジャッジ時間 3,921 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 27 ms
10,716 KB
testcase_05 AC 26 ms
10,716 KB
testcase_06 AC 25 ms
10,716 KB
testcase_07 AC 26 ms
10,716 KB
testcase_08 AC 31 ms
10,716 KB
testcase_09 AC 25 ms
10,716 KB
testcase_10 AC 25 ms
10,716 KB
testcase_11 AC 23 ms
10,716 KB
testcase_12 AC 24 ms
10,716 KB
testcase_13 AC 25 ms
10,716 KB
testcase_14 AC 24 ms
10,716 KB
testcase_15 AC 27 ms
10,716 KB
testcase_16 AC 24 ms
10,716 KB
testcase_17 AC 25 ms
10,716 KB
testcase_18 AC 24 ms
10,716 KB
testcase_19 AC 25 ms
10,716 KB
testcase_20 AC 25 ms
10,716 KB
testcase_21 AC 27 ms
10,716 KB
testcase_22 AC 25 ms
10,716 KB
testcase_23 AC 25 ms
10,716 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 1 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 3 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 1 ms
6,676 KB
testcase_41 AC 4 ms
6,676 KB
testcase_42 AC 1 ms
6,676 KB
testcase_43 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long mod = 998244353;
//入力が必ずmod未満の時に使う.
struct mint{
    long long v = 0;
    mint(){} mint(int a){v = a;} mint(long long a){v = a;} mint(unsigned long long a){v = a;}
    long long val(){return v;}
    void modu(){v %= mod;}
 
    mint repeat2mint(long long a,long long b){
        mint ret = 1,p = a; int Log = 60;
        if(b <= 2e9) Log = 30;
        for(int i=0; i<Log; i++){if(b&(1LL<<i)) ret *= p; p *= p;}
        return ret;
    };
 
    mint operator+(mint b){return (v+b.v)%mod;}
    mint operator-(mint b){return (v-b.v+mod)%mod;}
    mint operator*(mint b){return v*b.v%mod;}
    mint operator/(mint b){
        if(b.v == 0) assert(false);
        return v*(repeat2mint(b.v,mod-2)).v%mod;
    }
 
    void operator+=(mint b){v = (v+b.v)%mod;}
    void operator-=(mint b){v = (v-b.v+mod)%mod;}
    void operator*=(mint b){v = v*b.v%mod;}
    void operator/=(mint b){
    if(b.v == 0) assert(false);
        v = v*repeat2mint(b.v,mod-2).v%mod;
    }
 
    void operator++(int){v = (v+1)%mod; return;}
    void operator--(int){v = (v-1+mod)%mod; return;}
    bool operator==(mint b){if(v == b.v) return true; else return false;}
    bool operator!=(mint b){if(v != b.v) return true; else return false;}
    bool operator>(mint b){if(v > b.v) return true; else return false;}
    bool operator>=(mint b){if(v >= b.v) return true; else return false;}
    bool operator<(mint b){if(v < b.v) return true; else return false;}
    bool operator<=(mint b){if(v <= b.v) return true; else return false;}
 
    mint pow(long long x){return repeat2mint(v,x);}
    mint inv(){return mint(1)/v;}
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,K; cin >> N >> K;
    string s; cin >> s;

    vector<mint> fac(N+1,1),inv(N+1,1),facinv(N+1,1);
    for(int i=1; i<=N; i++) fac.at(i).v = fac.at(i-1).v*i %mod;
    for(int i=2; i<=N; i++) inv.at(i).v = mod-(mod/i*inv.at(mod%i).v %mod);
    for(int i=2; i<=N; i++) facinv.at(i).v = facinv.at(i-1).v*inv.at(i).v %mod;
    auto nCr = [&](int n, int r) -> mint {
        return fac.at(n)*facinv.at(r)*facinv.at(n-r);
    };
    
    int ok = 0;
    for(int i=0; i<N; i++){
        if(s.at(i) == 'N'){
            ok++;
            if(i) if(s.at(i-1) == 'C') K--,ok--;
        }
    }
    K = max(K,0);
    K = ok-K;

    mint answer = 0;
    for(int i=1; i<=K; i++) answer += nCr(ok,i);
    cout << answer.v << endl;
}
0