:heavy_check_mark: test/math/combination/atcoder_abc145_d.test.cpp

Depends on

Code

// verification-helper: PROBLEM https://atcoder.jp/contests/abc145/tasks/abc145_d

#include "src/math/combination.hpp"

#include <iostream>

using namespace std;

int main() {
	Combination<long long> comb;
	int x, y;
	cin >> x >> y;
	int xx = -x + 2 * y, yy = 2 * x - y;
	x = xx / 3, y = yy / 3;
	if (xx < 0 || yy < 0 || xx % 3 != 0 || yy % 3 != 0) cout << 0 << endl;
	else cout << comb.combination(x + y, x) << endl;

	return 0;
}
#line 1 "test/math/combination/atcoder_abc145_d.test.cpp"
// verification-helper: PROBLEM https://atcoder.jp/contests/abc145/tasks/abc145_d

#line 1 "src/math/combination.hpp"



#include <array>

template<class T, int SIZE = 1100000, T MOD = 1000000007>
class Combination {
private:
	std::array<T, SIZE> fac, finv, inv;

public:
	Combination() {
		fac[0] = fac[1] = inv[1] = finv[0] = finv[1] = 1;
		for (int i = 2; i < SIZE; ++i) {
			fac[i] = fac[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
			finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}

	T inverse(int n) { return inv[n]; }

	T factorial(int n) { return fac[n]; }

	T inverse_factorial(int n) { return finv[n]; }

	T permutation(int n, int r) {
		if (n < r || n < 0 || r < 0) return 0;
		return fac(n) * finv(n - r);
	}

	T combination(int n, int r) {
		if (n < r || n < 0 || r < 0) return 0;
		return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
	}
};


#line 4 "test/math/combination/atcoder_abc145_d.test.cpp"

#include <iostream>

using namespace std;

int main() {
	Combination<long long> comb;
	int x, y;
	cin >> x >> y;
	int xx = -x + 2 * y, yy = 2 * x - y;
	x = xx / 3, y = yy / 3;
	if (xx < 0 || yy < 0 || xx % 3 != 0 || yy % 3 != 0) cout << 0 << endl;
	else cout << comb.combination(x + y, x) << endl;

	return 0;
}

Test cases

Env Name Status Elapsed Memory
g++ hand_01 :heavy_check_mark: AC 50 ms 32 MB
g++ hand_02 :heavy_check_mark: AC 49 ms 33 MB
g++ hand_03 :heavy_check_mark: AC 48 ms 33 MB
g++ hand_04 :heavy_check_mark: AC 47 ms 33 MB
g++ random_01 :heavy_check_mark: AC 47 ms 33 MB
g++ random_02 :heavy_check_mark: AC 48 ms 32 MB
g++ random_03 :heavy_check_mark: AC 48 ms 32 MB
g++ random_04 :heavy_check_mark: AC 49 ms 32 MB
g++ random_05 :heavy_check_mark: AC 48 ms 33 MB
g++ random_06 :heavy_check_mark: AC 49 ms 32 MB
g++ random_07 :heavy_check_mark: AC 48 ms 32 MB
g++ random_08 :heavy_check_mark: AC 47 ms 32 MB
g++ random_09 :heavy_check_mark: AC 48 ms 33 MB
g++ random_10 :heavy_check_mark: AC 48 ms 32 MB
g++ random_11 :heavy_check_mark: AC 47 ms 33 MB
g++ random_12 :heavy_check_mark: AC 48 ms 32 MB
g++ random_13 :heavy_check_mark: AC 47 ms 33 MB
g++ random_14 :heavy_check_mark: AC 47 ms 32 MB
g++ random_15 :heavy_check_mark: AC 47 ms 33 MB
g++ random_16 :heavy_check_mark: AC 48 ms 32 MB
g++ random_17 :heavy_check_mark: AC 48 ms 33 MB
g++ random_18 :heavy_check_mark: AC 47 ms 33 MB
g++ random_19 :heavy_check_mark: AC 47 ms 32 MB
g++ random_20 :heavy_check_mark: AC 47 ms 33 MB
g++ random_21 :heavy_check_mark: AC 47 ms 33 MB
g++ random_22 :heavy_check_mark: AC 47 ms 32 MB
g++ random_23 :heavy_check_mark: AC 47 ms 32 MB
g++ random_24 :heavy_check_mark: AC 48 ms 33 MB
g++ sample_01 :heavy_check_mark: AC 47 ms 33 MB
g++ sample_02 :heavy_check_mark: AC 48 ms 32 MB
g++ sample_03 :heavy_check_mark: AC 48 ms 33 MB
clang++ hand_01 :heavy_check_mark: AC 34 ms 40 MB
clang++ hand_02 :heavy_check_mark: AC 35 ms 40 MB
clang++ hand_03 :heavy_check_mark: AC 35 ms 42 MB
clang++ hand_04 :heavy_check_mark: AC 34 ms 44 MB
clang++ random_01 :heavy_check_mark: AC 34 ms 44 MB
clang++ random_02 :heavy_check_mark: AC 35 ms 40 MB
clang++ random_03 :heavy_check_mark: AC 35 ms 38 MB
clang++ random_04 :heavy_check_mark: AC 33 ms 36 MB
clang++ random_05 :heavy_check_mark: AC 34 ms 40 MB
clang++ random_06 :heavy_check_mark: AC 34 ms 40 MB
clang++ random_07 :heavy_check_mark: AC 36 ms 42 MB
clang++ random_08 :heavy_check_mark: AC 34 ms 38 MB
clang++ random_09 :heavy_check_mark: AC 34 ms 38 MB
clang++ random_10 :heavy_check_mark: AC 34 ms 40 MB
clang++ random_11 :heavy_check_mark: AC 35 ms 36 MB
clang++ random_12 :heavy_check_mark: AC 34 ms 40 MB
clang++ random_13 :heavy_check_mark: AC 34 ms 40 MB
clang++ random_14 :heavy_check_mark: AC 35 ms 42 MB
clang++ random_15 :heavy_check_mark: AC 33 ms 38 MB
clang++ random_16 :heavy_check_mark: AC 34 ms 42 MB
clang++ random_17 :heavy_check_mark: AC 33 ms 38 MB
clang++ random_18 :heavy_check_mark: AC 34 ms 36 MB
clang++ random_19 :heavy_check_mark: AC 35 ms 38 MB
clang++ random_20 :heavy_check_mark: AC 35 ms 42 MB
clang++ random_21 :heavy_check_mark: AC 34 ms 44 MB
clang++ random_22 :heavy_check_mark: AC 34 ms 44 MB
clang++ random_23 :heavy_check_mark: AC 34 ms 40 MB
clang++ random_24 :heavy_check_mark: AC 36 ms 44 MB
clang++ sample_01 :heavy_check_mark: AC 35 ms 42 MB
clang++ sample_02 :heavy_check_mark: AC 35 ms 38 MB
clang++ sample_03 :heavy_check_mark: AC 35 ms 40 MB
Back to top page