結果
| 問題 |
No.1520 Zigzag Sum
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2021-05-13 23:28:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 51 ms / 2,000 ms |
| コード長 | 960 bytes |
| コンパイル時間 | 737 ms |
| コンパイル使用メモリ | 76,172 KB |
| 最終ジャッジ日時 | 2025-01-21 10:44:07 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
const ull M = 1000000007;
vector<ull> F,I,iF;
void init_comb(int Z){
F.assign(Z+1,1);
for(int i=1; i<=Z; i++) F[i] = F[i-1] * i % M;
I.assign(Z+1,1);
for(int i=2; i<=Z; i++) I[i] = M - M/i * I[M%i] % M;
iF.assign(Z+1,1);
for(int i=1; i<=Z; i++) iF[i] = iF[i-1] * I[i] % M;
}
ull comb(int n,int r){
return F[n] * iF[r] % M * iF[n-r] % M;
}
void testcase(){
int H,W; cin >> H >> W;
if(H == 1 || W == 1){
cout << 0 << "\n";
return;
}
ull ans = comb((H-2)+(W-2),H-2) * ((H-1)+(W-1)-1) % M * 2 % M;
cout << ans << "\n";
}
int main(){
int T; cin >> T;
init_comb(400000);
rep(caseid,T) testcase();
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia