結果

問題 No.1520 Zigzag Sum
ユーザー chocoruskchocorusk
提出日時 2021-06-18 01:42:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 212 ms / 2,000 ms
コード長 1,225 bytes
コンパイル時間 3,481 ms
コンパイル使用メモリ 188,196 KB
実行使用メモリ 19,296 KB
最終ジャッジ日時 2023-09-02 13:10:47
合計ジャッジ時間 6,600 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
19,040 KB
testcase_01 AC 11 ms
18,980 KB
testcase_02 AC 188 ms
19,296 KB
testcase_03 AC 212 ms
18,988 KB
testcase_04 AC 208 ms
19,292 KB
testcase_05 AC 203 ms
19,028 KB
testcase_06 AC 206 ms
19,020 KB
testcase_07 AC 205 ms
19,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
using mint=modint1000000007;
mint f[2000010], invf[2000010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i;
    invf[n]=f[n].inv();
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1);
}
mint comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]*invf[x-y];
}
int main()
{
    int t; cin>>t;
    fac(400000);
    while(t--){
        int h, w;
        cin>>h>>w;
        if(h==1 || w==1){
            cout<<0<<endl;
        }else{
            h--; w--;
            mint ans=mint(h+w-1)*mint(2)*comb(h+w-2, h-1);
            cout<<ans.val()<<endl;
        }
    }
    return 0;
}
0