Submission #19776

# Submission time Handle Problem Language Result Execution time Memory
19776 2016-02-25T05:30:25 Z gs13068 괄호 (kriii4_R) C++
100 / 100
596 ms 8896 KB
#include <cstdio>

const int p = 1000000007;

int pw(int x, int y)
{
	return y & 1 ? (long long)pw(x, y ^ 1)*x%p : y ? pw((long long)x*x%p, y >> 1) : 1;
}

int fac[2000002];

int calc(int i, int j)
{
	if (i < j) return 0;
	if (i + j & 1) return 0;
	int r = j + 1;
	if (i & 1)
	{
		r = (long long)r * fac[i] % p;
		r = (long long)r * pw(fac[(i + j) / 2 + 1], p - 2) % p;
		r = (long long)r * pw(fac[(i - j) / 2], p - 2) % p;
	}
	else
	{
		r = (long long)r * fac[i] % p;
		r = (long long)r * pw(fac[(i + j) / 2 + 1], p - 2) % p;
		r = (long long)r * pw(fac[(i - j) / 2], p - 2) % p;
	}
	return r;
}

int main()
{
	int i, n, m, r = 0;
	fac[0] = 1;
	for (i = 1; i <= 2000000; i++) fac[i] = (long long)fac[i - 1] * i % p;
	scanf("%d%d", &n, &m);
	for (i = 0; i <= n; i++) r = (r + (long long)calc(n, i)*pw(m, n + i >> 1)) % p;
	printf("%d", r);
}
# Verdict Execution time Memory Grader output
1 Correct 186 ms 8896 KB Output is correct
2 Correct 50 ms 8896 KB Output is correct
3 Correct 439 ms 8896 KB Output is correct
4 Correct 490 ms 8896 KB Output is correct
5 Correct 496 ms 8896 KB Output is correct
6 Correct 276 ms 8896 KB Output is correct
7 Correct 314 ms 8896 KB Output is correct
8 Correct 209 ms 8896 KB Output is correct
9 Correct 92 ms 8896 KB Output is correct
10 Correct 31 ms 8896 KB Output is correct
11 Correct 37 ms 8896 KB Output is correct
12 Correct 448 ms 8896 KB Output is correct
13 Correct 425 ms 8896 KB Output is correct
14 Correct 189 ms 8896 KB Output is correct
15 Correct 199 ms 8896 KB Output is correct
16 Correct 185 ms 8896 KB Output is correct
17 Correct 547 ms 8896 KB Output is correct
18 Correct 558 ms 8896 KB Output is correct
19 Correct 595 ms 8896 KB Output is correct
20 Correct 596 ms 8896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 169 ms 8896 KB Output is correct
2 Correct 64 ms 8896 KB Output is correct
3 Correct 116 ms 8896 KB Output is correct
4 Correct 539 ms 8896 KB Output is correct
5 Correct 339 ms 8896 KB Output is correct
6 Correct 417 ms 8896 KB Output is correct
7 Correct 283 ms 8896 KB Output is correct
8 Correct 166 ms 8896 KB Output is correct
9 Correct 287 ms 8896 KB Output is correct
10 Correct 50 ms 8896 KB Output is correct
11 Correct 470 ms 8896 KB Output is correct
12 Correct 490 ms 8896 KB Output is correct
13 Correct 458 ms 8896 KB Output is correct
14 Correct 217 ms 8896 KB Output is correct
15 Correct 275 ms 8896 KB Output is correct
16 Correct 277 ms 8896 KB Output is correct
17 Correct 53 ms 8896 KB Output is correct
18 Correct 595 ms 8896 KB Output is correct
19 Correct 592 ms 8896 KB Output is correct
20 Correct 591 ms 8896 KB Output is correct