結果

問題 No.1520 Zigzag Sum
ユーザー aspiaspi
提出日時 2021-05-28 19:13:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 4,328 bytes
コンパイル時間 1,307 ms
コンパイル使用メモリ 134,456 KB
実行使用メモリ 27,156 KB
最終ジャッジ日時 2023-08-07 03:47:49
合計ジャッジ時間 3,650 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
27,024 KB
testcase_01 AC 31 ms
27,004 KB
testcase_02 AC 210 ms
27,032 KB
testcase_03 AC 228 ms
27,076 KB
testcase_04 AC 229 ms
27,016 KB
testcase_05 AC 228 ms
27,076 KB
testcase_06 AC 222 ms
27,020 KB
testcase_07 AC 222 ms
27,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <ctime>
#include <stdlib.h>
#include <math.h>
#include <numeric>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <fstream> 
#include <sstream>
#include <random>
#include <chrono>
using namespace std;

/*
#include <atcoder/all>
using namespace atcoder;
using mf_edge = mf_graph<int>::edge;
*/


/*
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/


#define endl "\n"
#define ALL(v)  v.begin(),v.end()
#define m_p make_pair
#define m_t make_tuple
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
using P = pair<int, int>;
using ld = long double;
using ll = long long;
using VI = vector<int>;
using time_point = chrono::system_clock::time_point;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
template<class T> using PQ = priority_queue<T>;


constexpr double pai = 3.1415926535897;
constexpr int INF = 1000000021;
constexpr long long LINF = 2000000000000000000;
const long long mod = 1000000007;
const long long MOD = mod;
constexpr double PI = 3.1415926;
const vector<int> ver = { 1,0,-1,0 }, sid{ 0,1,0,-1 };

struct edge {
	int to, cost;
};
edge m_e(int xx, int yy) {
	edge ed;
	ed.to = xx;
	ed.cost = yy;
	return ed;
}


template<class T>void vecin(vector<T>& v) { for (int i = 0; i < (int)v.size(); i++) cin >> v[i]; }

template<class T>bool chmax(T& xx, T yy) { if (xx < yy) { xx = yy; return true; }return false; }
template<class T>bool chmin(T& xx, T yy) { if (xx > yy) { xx = yy; return true; }return false; }
//x未満の要素数を返す二分探索関数
int b_s(vector<int>& vec, int xx) { return lower_bound(ALL(vec), xx) - vec.begin(); }
int gcd(int xx, int yy) {
	if (yy > xx)swap(xx, yy);
	while (xx % yy != 0) {
		xx %= yy;
		swap(xx, yy);
	}
	return yy;
}
int lcm(int xx, int yy) { return (xx / gcd(xx, yy)) * yy; }
bool prime(int xx) {//O(sqrt(N))
	if (xx <= 1)return 0;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0)return 0;
	}
	return 1;
}


constexpr int MAX = 1010000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll PER(int n, int k) {
	if (n < 0 || k < 0) return 0;
	if (n < k) return fac[n];
	return fac[n] * finv[n - k] % mod;
}
long long modinv(long long a, long long m) {//a*u≡1(mod m)
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


std::random_device seed_gen;
std::mt19937 engine(seed_gen());
class xorshift {
	uint64_t seed;
public:
	xorshift() { seed = (uint64_t(seed_gen()) << 32) + seed_gen(); }
	inline uint64_t get64() {
		seed ^= (seed << 13); seed ^= (seed >> 7);
		return seed ^= (seed << 17);
	}
	inline uint32_t operator()() { return get64(); }
	inline uint32_t operator()(uint32_t r) { return get64() % r; }
	inline int operator()(int mi, int ma) { return mi + operator()(ma - mi); }
	inline double prob() { return double(operator()()) / 0xffffffff; }
}myrand;

time_point start_time;
void get_time(chrono::system_clock::time_point& x) {
	x = chrono::system_clock::now();
}
int my_clock(chrono::system_clock::time_point start) {
	return static_cast<int>(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count());
}





int main() {
	COMinit();
	int T, H, W;
	cin >> T;
	rep(i, T) {
		cin >> H >> W;
		int ans = 2ll * ll(H + W - 3) * COM(H + W - 4, H - 2) % mod;
		if (ans < 0)ans += mod;
		cout << ans << endl;
	}
}
0