結果

問題 No.2792 Security Cameras on Young Diagram
ユーザー srjywrdnprkt
提出日時 2024-07-03 09:31:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 1,832 ms
コンパイル使用メモリ 195,312 KB
最終ジャッジ日時 2025-02-22 01:53:48
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:36:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
main.cpp:39:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |         scanf("%d", &A);
      |         ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

const int MAX=2e5;

mint f[MAX+1], finv[MAX+1];

mint inv(mint x){
    mint ans = 1;
    int e = 998244351;

    while (e > 0){
        if ((e & 1)) ans *= x;
        e >>= 1;
        x *= x;
    }

    return ans;
}

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

    f[0] = 1;
    for (int i=1; i<=MAX; i++) f[i] = f[i-1]*i;
    finv[MAX] = inv(f[MAX]);
    for (int i=MAX-1; i>=0; i--) finv[i] = finv[i+1] * (i+1);

    int N, A;
    scanf("%d", &N);
    mint ans=0;
    for (int i=0; i<N; i++){
        scanf("%d", &A);
        ans += f[A+i] * finv[i+1] * finv[A-1];
    }
    printf("%d", (ans+1).val());

    return 0;
}
0