結果
| 問題 |
No.1520 Zigzag Sum
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2021-06-18 01:42:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 264 ms / 2,000 ms |
| コード長 | 1,225 bytes |
| コンパイル時間 | 3,270 ms |
| コンパイル使用メモリ | 181,724 KB |
| 最終ジャッジ日時 | 2025-01-22 08:39:34 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 |
ソースコード
#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;
}
chocorusk