結果

問題 No.1520 Zigzag Sum
ユーザー 👑 NachiaNachia
提出日時 2021-05-13 23:28:53
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 960 bytes
コンパイル時間 788 ms
コンパイル使用メモリ 77,344 KB
実行使用メモリ 12,580 KB
最終ジャッジ日時 2023-10-26 03:39:37
合計ジャッジ時間 2,049 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,580 KB
testcase_01 AC 16 ms
12,580 KB
testcase_02 AC 39 ms
12,580 KB
testcase_03 AC 53 ms
12,580 KB
testcase_04 AC 53 ms
12,580 KB
testcase_05 AC 55 ms
12,580 KB
testcase_06 AC 44 ms
12,580 KB
testcase_07 AC 43 ms
12,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;

0