結果
| 問題 | No.2572 Midori on the grid | 
| コンテスト | |
| ユーザー |  momoyuu | 
| 提出日時 | 2023-12-15 15:40:11 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,480 ms / 5,000 ms | 
| コード長 | 1,292 bytes | 
| コンパイル時間 | 1,160 ms | 
| コンパイル使用メモリ | 102,416 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-27 06:26:26 | 
| 合計ジャッジ時間 | 12,214 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 8 | 
ソースコード
#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;
        }
    }
}
            
            
            
        