QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#663561#7056. ChessboardLoxilanteTL 0ms3560kbC++141.2kb2024-10-21 16:11:362024-10-21 16:11:39

Judging History

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

  • [2024-10-21 16:11:39]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3560kb
  • [2024-10-21 16:11:36]
  • 提交

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 p = 1000000007;
ll qpow(ll a,ll b){
	if(b==1) return a;
	ll t=qpow(a,b/2);
	t=t*t%p;
	if(b&1) t=t*a%p;
	return t;
}
ll C(ll n,ll m){
	if(n<m) return 0;
	if(m>n-m) m=n-m;
	ll a=1,b=1;
	for(int i=0;i<m;i++){
		a=(a*(n-i))%p;
		b=(b*(i+1))%p;
	}
	return a*qpow(b,p-2)%p;
}
ll lucas(ll n,ll m){
	if(m==0) return 1;
	return lucas(n/p,m/p)*C(n%p,m%p)%p;
}
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;
}
/*

 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: