QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#738389#7056. Chessboardicpc_zhzx034#AC ✓29ms35132kbC++141.6kb2024-11-12 18:56:302024-11-12 18:56:30

Judging History

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

  • [2024-11-12 18:56:30]
  • 评测
  • 测评结果:AC
  • 用时:29ms
  • 内存:35132kb
  • [2024-11-12 18:56:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define mkp make_pair
#define pb emplace_back
#define popcnt __builtin_popcountll
const ll mod = 1e9+7;
inline ll read(){
	ll x=0, f=1; char ch=getchar();
	while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
	while(ch>='0' && ch<='9') x=x*10+ch-'0', ch=getchar();
	return x*f;
}
inline ll lg2(ll x){ return 63^__builtin_clzll(x); }
inline ll qpow(ll a,ll b){
	ll ans=1, base=a;
	while(b){
		if(b&1) ans=ans*base%mod;
		base=base*base%mod; b>>=1;
	}
	return ans;
}
namespace math{
	const ll N = 2000000;
	ll fac[N+5],inv[N+5];
	ll qpow(ll a,ll b){
		ll ans=1,base=a;
		while(b){
			if(b&1) ans=ans*base%mod;
			base=base*base%mod; b>>=1;
		}
		return ans;
	}
	void init(){
		fac[0]=inv[0]=1;
		for(ll i=1;i<=N;i++) fac[i]=fac[i-1]*i%mod;
		inv[N]=qpow(fac[N],mod-2);
		for(ll i=N-1;i>=1;i--) inv[i]=inv[i+1]*(i+1)%mod;
	}
	inline ll binom(ll x,ll y){
		if(x<0 || y<0 || x<y) return 0;
		return fac[x]*inv[y]%mod*inv[x-y]%mod;
	}
	inline ll perm(ll x,ll y){
		if(x<0 || y<0 || x<y) return 0;
		return fac[x]*inv[x-y]%mod;
	}
}
void init(){ }

ll n,m;
void procedure(){
	n=read(), m=read();
	if(n==1 || m==1){
		puts(n==m?"1":"2");
		return;
	}
	printf("%llu\n", 4ull * math::binom(n+m-2, n-1) % mod);
}
int main(){
	#ifdef LOCAL
		assert(freopen("input.txt","r",stdin));
		assert(freopen("output.txt","w",stdout));
	#endif
	math::init();
	ll T=read();
	init();
	while(T--) procedure();
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 15ms
memory: 35132kb

input:

4
1 3
3 2
3 3
4 4

output:

2
12
24
80

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 29ms
memory: 35020kb

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
924670542
949970465
966074148
738866875
850972524
188501202
415300991
348587010
83136096
868751565
382630270
84169254
853440534
896111017
757449222
159729268
314963625
123541563
930525180
843770156
720106956
738036168
297993327
601767944
38907892
236214827
455317099
254577850
272370955
239...

result:

ok 100000 lines