結果

問題 No.1520 Zigzag Sum
ユーザー aspi
提出日時 2021-05-28 19:13:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 337 ms / 2,000 ms
コード長 4,328 bytes
コンパイル時間 1,256 ms
コンパイル使用メモリ 131,104 KB
最終ジャッジ日時 2025-01-21 18:59:00
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

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;
}
}
//n1xcom(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;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0