QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#817169#7056. ChessboardSGColinAC ✓27ms19468kbC++201.1kb2024-12-16 20:42:332024-12-16 20:42:34

Judging History

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

  • [2024-12-16 20:42:34]
  • 评测
  • 测评结果:AC
  • 用时:27ms
  • 内存:19468kb
  • [2024-12-16 20:42:33]
  • 提交

answer

#include <bits/stdc++.h>
#define double long double
using namespace std;

inline int rd() {
	int x = 0;
	bool f = 0;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) f |= (c == '-');
	for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
	return f ? -x : x;
}

#define N 2000007
#define mod 1000000007

inline int fpow(int x, int t) {
	int res = 1;
	for (; t; t >>= 1, x = 1ll * x * x % mod)
		if (t & 1) res = 1ll * res * x % mod;
	return res;
}

int fac[N], ifac[N];

inline void init() {
	fac[0] = ifac[0] = 1;
	for (int i = 1; i < N; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
	ifac[N - 1] = fpow(fac[N - 1], mod - 2);
	for (int i = N - 2; i; --i) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % mod;
}

inline int C(int n, int m) {
	return 1ll * fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}

inline void work() {
	int n = rd(), m = rd();
	if (n > m) swap(n, m);
	if (n == 1) {
		puts(m == 1 ? "1" : "2"); return;
	}
	printf("%d\n", 4ll * C(n + m - 2, n - 1) % mod);
}

int main() {
	init();
	for (int t = rd(); t; --t) work();
	return 0;
}

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

详细

Test #1:

score: 100
Accepted
time: 17ms
memory: 19404kb

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: 27ms
memory: 19468kb

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