結果

問題 No.2792 Security Cameras on Young Diagram
ユーザー GOTKAKOGOTKAKO
提出日時 2024-06-21 21:40:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 2,527 bytes
コンパイル時間 2,060 ms
コンパイル使用メモリ 206,612 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-06-24 18:44:38
合計ジャッジ時間 3,252 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,936 KB
testcase_01 AC 17 ms
7,808 KB
testcase_02 AC 17 ms
7,936 KB
testcase_03 AC 16 ms
7,936 KB
testcase_04 AC 16 ms
7,936 KB
testcase_05 AC 16 ms
7,936 KB
testcase_06 AC 17 ms
7,936 KB
testcase_07 AC 17 ms
7,808 KB
testcase_08 AC 17 ms
7,936 KB
testcase_09 AC 17 ms
7,808 KB
testcase_10 AC 17 ms
7,936 KB
testcase_11 AC 17 ms
7,808 KB
testcase_12 AC 25 ms
8,064 KB
testcase_13 AC 23 ms
8,064 KB
testcase_14 AC 24 ms
8,064 KB
testcase_15 AC 21 ms
7,808 KB
testcase_16 AC 23 ms
8,064 KB
testcase_17 AC 26 ms
8,064 KB
testcase_18 AC 20 ms
7,936 KB
testcase_19 AC 19 ms
7,936 KB
testcase_20 AC 20 ms
8,064 KB
testcase_21 AC 16 ms
7,808 KB
testcase_22 AC 17 ms
7,808 KB
testcase_23 AC 28 ms
8,320 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(const long long a,long long b){
        mint ret = 1,p = a;
        while(b){
            if(b&1) ret *= p;
            p *= p; b >>= 1;
        }
        return ret;
    };
 
    mint operator+(const mint b){return mint(v)+=b;}
    mint operator-(const mint b){return mint(v)-=b;}
    mint operator*(const mint b){return mint(v)*=b;}
    mint operator/(const mint b){return mint(v)/=b;}
 
    mint operator+=(const mint b){
        v += b.v; if(v >= mod) v -= mod;
        return *this;
    }
    mint operator-=(const mint b){
        v -= b.v; if(v < 0) v += mod; 
        return *this;
    }   
    mint operator*=(const mint b){v = v*b.v%mod; return *this;}
    mint operator/=(mint b){
        if(b == 0) assert(false);
        int left = mod-2;
        while(left){if(left&1) *this *= b; b *= b; left >>= 1;}
        return *this;
    }
 
    mint operator++(int){*this += 1; return *this;}
    mint operator--(int){*this -= 1; return *this;}
    bool operator==(const mint b){return v == b.v;}
    bool operator!=(const mint b){return v != b.v;}
    bool operator>(const mint b){return v > b.v;}
    bool operator>=(const mint b){return v >= b.v;}
    bool operator<(const mint b){return v < b.v;}
    bool operator<=(const mint b){return v <= b.v;}
    
    mint pow(const 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; cin >> N;
    vector<int> A(N);
    for(auto &a : A) cin >> a;

    int Limit = 200009;
    vector<mint> fac(Limit+1,1),inv(Limit+1,1),facinv(Limit+1,1);
    for(int i=1; i<=Limit; i++) fac.at(i).v = fac.at(i-1).v*i %mod;
    for(int i=2; i<=Limit; i++) inv.at(i).v = mod-(mod/i*inv.at(mod%i).v %mod);
    for(int i=2; i<=Limit; i++) facinv.at(i).v = facinv.at(i-1).v*inv.at(i).v %mod;
    auto nCr = [&](int n, int r) -> mint {
        //if(n < r || r < 0 || n < 0) return mint(0);
        return fac.at(n)*facinv.at(r)*facinv.at(n-r);
    };

    mint answer = 0;
    int D = 0;
    for(int i=N-1; i>=0; i--){
        int a = A.at(i);
        while(D <= a){
            answer += nCr(D+i,i);
            D++;
        }
    }
    cout << answer.v << endl;
}
0