Submission #67790842


Source Code Expand

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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef double db;

const int mod = 998244353;

int add(int a, int b)
{
	return a + b < mod ? a + b : a + b - mod;
}

void updAdd(int& a, int b)
{
	a += b;
	if (a >= mod)
		a -= mod;
}

int sub(int a, int b)
{
	return a - b >= 0 ? a - b : a - b + mod;
}

void updSub(int& a, int b)
{
	a -= b;
	if (a < 0)
		a += mod;
}

int mult(int a, int b)
{
	return (LL)a * b % mod;
}

int binpow(int a, LL n)
{
	int res = 1;
	while (n)
	{
		if (n & 1)
			res = mult(res, a);
		a = mult(a, a);
		n /= 2;
	}
	return res;
}

const int N = 1 << 20;

int inv[N], fact[N], ifact[N];

void init()
{
	inv[1] = 1;
	FOR(i, 2, N)
	{
		inv[i] = mult(mod - mod / i, inv[mod % i]);
	}
	fact[0] = ifact[0] = 1;
	FOR(i, 1, N)
	{
		fact[i] = mult(fact[i - 1], i);
		ifact[i] = mult(ifact[i - 1], inv[i]);
	}
}

int C(int n, int k)
{
	if (k < 0 || k > n)
		return 0;
	return mult(fact[n], mult(ifact[n - k], ifact[k]));
}

/*int H(int n, int k)
{
	return C(n + k - 1, n - 1);
}*/

template<typename T>
void updMin(T& a, T b)
{
	a = min(a, b);
}

template<typename T>
void updMax(T& a, T b)
{
	a = max(a, b);
}

int main()
{
	ios::sync_with_stdio(0); 
	cin.tie(0);
	init();
	int h, w;
	cin >> h >> w;
	if (h % 2 == 0)
	{
		cout << "0\n";
		return 0;
	}
	if (w % 2 == 1)
	{
		int ans = 0;
		for (int d = 1; d <= h; d += 2)
		{
			if (gcd(d, w) == 1)
				updAdd(ans, C(h, (h + d) / 2));
		}
		ans = mult(ans, 2);
		cout << ans << "\n";
		return 0;
	}
	h *= 2;
	int ans = 0;
	for (int d = 0; d <= h; d += 2)
	{
		if (gcd(d, w) == 2)
			updAdd(ans, C(h, (h + d) / 2));
	}
	ans = mult(ans, 2);
	cout << ans << "\n";
	return 0;
}

Submission Info

Submission Time
Task B - Japanese "Knight's Tour"
User mshcherba
Language C++ 20 (gcc 12.2)
Score 800
Code Size 2152 Byte
Status AC
Exec Time 26 ms
Memory 15892 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 3
AC × 41
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 03_max_00.txt, 03_max_01.txt, 03_max_02.txt, 03_max_03.txt, 03_max_04.txt, 03_max_05.txt, 03_max_06.txt, 03_max_07.txt, 03_max_08.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 14 ms 15812 KiB
00_sample_01.txt AC 14 ms 15620 KiB
00_sample_02.txt AC 15 ms 15624 KiB
01_small_00.txt AC 14 ms 15676 KiB
01_small_01.txt AC 14 ms 15620 KiB
01_small_02.txt AC 14 ms 15812 KiB
01_small_03.txt AC 14 ms 15752 KiB
01_small_04.txt AC 14 ms 15760 KiB
01_small_05.txt AC 14 ms 15760 KiB
01_small_06.txt AC 14 ms 15892 KiB
01_small_07.txt AC 14 ms 15764 KiB
01_small_08.txt AC 14 ms 15888 KiB
02_random_00.txt AC 14 ms 15696 KiB
02_random_01.txt AC 20 ms 15708 KiB
02_random_02.txt AC 14 ms 15764 KiB
02_random_03.txt AC 18 ms 15816 KiB
02_random_04.txt AC 15 ms 15820 KiB
02_random_05.txt AC 23 ms 15752 KiB
02_random_06.txt AC 20 ms 15752 KiB
02_random_07.txt AC 16 ms 15692 KiB
02_random_08.txt AC 15 ms 15760 KiB
02_random_09.txt AC 16 ms 15764 KiB
02_random_10.txt AC 26 ms 15888 KiB
02_random_11.txt AC 23 ms 15816 KiB
02_random_12.txt AC 15 ms 15752 KiB
02_random_13.txt AC 17 ms 15760 KiB
02_random_14.txt AC 14 ms 15620 KiB
02_random_15.txt AC 23 ms 15748 KiB
02_random_16.txt AC 19 ms 15680 KiB
02_random_17.txt AC 20 ms 15676 KiB
02_random_18.txt AC 20 ms 15620 KiB
02_random_19.txt AC 14 ms 15704 KiB
03_max_00.txt AC 14 ms 15764 KiB
03_max_01.txt AC 14 ms 15740 KiB
03_max_02.txt AC 14 ms 15748 KiB
03_max_03.txt AC 26 ms 15680 KiB
03_max_04.txt AC 21 ms 15636 KiB
03_max_05.txt AC 25 ms 15748 KiB
03_max_06.txt AC 14 ms 15756 KiB
03_max_07.txt AC 14 ms 15684 KiB
03_max_08.txt AC 14 ms 15736 KiB