QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#663547#7056. ChessboardLoxilanteTL 0ms3724kbC++141.3kb2024-10-21 16:07:182024-10-21 16:07:20

Judging History

你现在查看的是最新测评结果

  • [2024-10-21 16:07:20]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3724kb
  • [2024-10-21 16:07:18]
  • 提交

answer

#define F_C
#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = l; i < r; i++)
#define hrp(i, l, r) for(int i = l; i <= r; i++)
#define rev(i, r, l) for(int i = r; i >= l; i--)
#define int ll
using namespace std;
typedef long long ll;
template<typename tn = int> tn next(void) { tn k; cin>>k; return k; }
#ifndef LOCAL
#define D(...) 0
#endif
const int MOD = 1000000007;
int quickPow(int a, int b)
{
	int ret = 1%MOD, t = a;
	while(b)
	{
		if (b & 1) ret = ret*t%MOD;
		t = t*t%MOD;
		b >>= 1;
	}
	return ret;
}
inline int inv(int x)
{
	return quickPow(x, MOD-2);
}
int C(int n, int m)
{
	if (m > n) return 0;
	int u = 1, d = 1;
	hrp(i, n-m+1, n) u = u*i%MOD;
	hrp(i, 1, m) d = d*i%MOD;
	return u*inv(d)%MOD;
}
int lucas(int n, int m)
{
	if (m == 0) return 1;
	return C(n%MOD, m%MOD)*lucas(n/MOD, m/MOD)%MOD;
}
signed main(void)
{
    #ifdef LOCAL
//	freopen("C:\\Users\\Loxil\\Desktop\\IN.txt", "r", stdin);
//	freopen("C:\\Users\\Loxil\\Desktop\\OUT.txt", "w", stdout);
    #endif
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int T = next();
    while(T--)
    {
        int n, m;
        cin>>n>>m;
        if (n+m == 2) cout<<1<<endl;
        else if (n == 1 || m == 1) cout<<2<<endl;
        else cout<<4*lucas(n+m-2, n-1)<<endl;
    }
    
    return 0;
}
/*

 */

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3724kb

input:

4
1 3
3 2
3 3
4 4

output:

2
12
24
80

result:

ok 4 lines

Test #2:

score: -100
Time Limit Exceeded

input:

100000
15792 12672
9316 25840
2840 1766
6041 11358
24545 23695
6867 5451
20360 1937
16422 30090
29793 9605
10515 14761
21907 31360
15532 21121
28260 27461
2296 8459
15031 26552
21401 21622
27858 22934
7596 28278
12389 27492
7921 25054
7880 15269
31788 32625
18565 20560
15563 9461
30742 24193
17352 2...

output:

110567924
2924670556
1949970472
966074148
3738866896
850972524
2188501216
3415301012
2348587024
83136096
1868751572
2382630284
2084169268
2853440548
1896111024
2757449236
159729268
1314963632
3123541584
930525180
843770156
720106956
738036168
3297993348
601767944
38907892
3236214848
3455317120
22545...

result: