結果

問題 No.2572 Midori on the grid
ユーザー momoyuumomoyuu
提出日時 2023-12-15 15:40:11
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,449 ms / 5,000 ms
コード長 1,292 bytes
コンパイル時間 1,056 ms
コンパイル使用メモリ 101,964 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-15 15:40:23
合計ジャッジ時間 12,181 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,449 ms
6,676 KB
testcase_01 AC 737 ms
6,676 KB
testcase_02 AC 1,164 ms
6,676 KB
testcase_03 AC 1,100 ms
6,676 KB
testcase_04 AC 560 ms
6,676 KB
testcase_05 AC 1,152 ms
6,676 KB
testcase_06 AC 56 ms
6,676 KB
testcase_07 AC 56 ms
6,676 KB
testcase_08 AC 56 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;


#include<atcoder/modint>
using mint = atcoder::modint998244353;

mint fac[3<<17],ifac[3<<17];

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

    fac[0] = 1;
    for(int i = 1;i<3<<17;i++) fac[i] = fac[i-1] * i;
    for(int i = 0;i<3<<17;i++) ifac[i] = fac[i].inv();
    ll h,w,q;
    cin>>h>>w>>q;
    int n = h;
    int m = w;
    while(q--){
        ll t;
        cin>>t;
        ll nt = w - 0;
        mint tmp = fac[h+w] * ifac[h] * ifac[w];
        if(t>nt) {
            cout<<tmp.val()<<endl;
            continue;
        }
        nt = 0 - h;
        if(t<nt){
            cout<<tmp.val()<<endl;
            continue;
        }
        bool fn = true;
        if(0-0<t&&w-h>t) fn = false;
        if(0-0>t&&w-h<t) fn = false;
        if(!fn){
            cout<<0<<endl;
            continue;
        }
        if(t>0){
            ll y = 0 + t;
            ll k = w - y;
            k++;
            tmp -= fac[n+m] * ifac[k-1] * ifac[n+m-k+1];
            cout<<tmp.val()<<endl;;
        }else{
            ll x = -t;
            ll k = h - x + 1;
            tmp -= fac[n+m] * ifac[k-1] * ifac[n+m-k+1];
            cout<<tmp.val()<<endl;
        }
    }
}
0