Submission #67787261


Source Code Expand

// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <chrono>
#include <random>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
#include <array>
#define dibs reserve
#define OVER9000 1234567890123456789LL
#define tisic 47
#define soclose 1e-8
#define patkan 9
#define ff first
#define ss second
using uint = unsigned int;
using cat = long long;
using dbl = long double;
constexpr dbl pi = 3.14159265358979323846;
using namespace std;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

template <typename T>
T abs(T x) { return (x < 0) ? (-x) : x; }

cat gcd(cat a, cat b) {
	if(a > b) swap(a, b);
	while(a) {
		cat c = b%a;
		b = a;
		a = c;
	}
	return b;
}

cat pw(cat a, cat e, cat mod) {
	if(e <= 0) return 1;
	cat x = pw(a, e/2, mod);
	x = x * x % mod;
	return (e&1) ? x * a % mod : x;
}

template <typename T>
class fin {
	vector<T> node_val;

	int lastone(int x) { return x & (x ^ (x-1)); }

public:
	fin(int N, T init_val) {
		node_val.resize(N+10, init_val);
	}

	void put(int pos, T val) {
		for(int i = pos+1; i < (int)node_val.size(); i += lastone(i))
			node_val[i] += val;
	}

	T get(int pos) {
		T ret = 0;
		for(int i = pos+1; i > 0; i -= lastone(i))
			ret += node_val[i];
		return ret;
	}
};

constexpr cat MOD = 998244353;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(12);
	int H, W;
	cin >> H >> W;
	if(H%2 == 0) {
		cout << "0\n";
		return 0;
	}
	vector<cat> fac(2*H+1, 1);
	for(int i = 1; i <= 2*H; i++) fac[i] = fac[i-1] * i % MOD;
	vector<cat> fac_inv(2*H+1);
	fac_inv[2*H] = pw(fac[2*H], MOD-2, MOD);
	for(int i = 2*H; i > 0; i--) fac_inv[i-1] = fac_inv[i] * i % MOD;
	if(W%2 != 0) {
		cat ans = 0;
		for(int np = 0; np <= H; np++) {
			int d = (np - (H-np)) % W;
			if(d < 0) d += W;
			if(d == 0 || gcd(d, W) != 1) continue;
			ans = (ans + fac[H] * fac_inv[np] % MOD * fac_inv[H-np]) % MOD;
		}
		cout << ans << "\n";
	}
	else {
		cat ans = 0;
		for(int d0 = 1; d0 <= H; d0++) { // np - nm
			int d = d0 % (W/2);
			if(d < 0) d += (W/2);
			if(d == 0 || gcd(d, W/2) != 1) continue;
			ans = (ans + 2 * fac[2*H] * fac_inv[H+d0] % MOD * fac_inv[H-d0]) % MOD;
		}
		cout << ans << "\n";
	}
}

// look at my code
// my code is amazing

Submission Info

Submission Time
Task B - Japanese "Knight's Tour"
User xellos
Language C++ 20 (gcc 12.2)
Score 800
Code Size 2586 Byte
Status AC
Exec Time 19 ms
Memory 9408 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 1 ms 3608 KiB
00_sample_01.txt AC 1 ms 3460 KiB
00_sample_02.txt AC 1 ms 3444 KiB
01_small_00.txt AC 1 ms 3480 KiB
01_small_01.txt AC 1 ms 3420 KiB
01_small_02.txt AC 1 ms 3392 KiB
01_small_03.txt AC 1 ms 3604 KiB
01_small_04.txt AC 1 ms 3432 KiB
01_small_05.txt AC 1 ms 3524 KiB
01_small_06.txt AC 1 ms 3456 KiB
01_small_07.txt AC 1 ms 3456 KiB
01_small_08.txt AC 1 ms 3528 KiB
02_random_00.txt AC 1 ms 3480 KiB
02_random_01.txt AC 10 ms 6164 KiB
02_random_02.txt AC 1 ms 3468 KiB
02_random_03.txt AC 12 ms 7040 KiB
02_random_04.txt AC 1 ms 3564 KiB
02_random_05.txt AC 14 ms 7816 KiB
02_random_06.txt AC 10 ms 6736 KiB
02_random_07.txt AC 4 ms 4064 KiB
02_random_08.txt AC 2 ms 3532 KiB
02_random_09.txt AC 7 ms 5420 KiB
02_random_10.txt AC 17 ms 9048 KiB
02_random_11.txt AC 13 ms 7760 KiB
02_random_12.txt AC 6 ms 4600 KiB
02_random_13.txt AC 9 ms 5724 KiB
02_random_14.txt AC 2 ms 3420 KiB
02_random_15.txt AC 15 ms 8520 KiB
02_random_16.txt AC 8 ms 5944 KiB
02_random_17.txt AC 10 ms 6980 KiB
02_random_18.txt AC 10 ms 6948 KiB
02_random_19.txt AC 1 ms 3540 KiB
03_max_00.txt AC 1 ms 3324 KiB
03_max_01.txt AC 1 ms 3460 KiB
03_max_02.txt AC 1 ms 3472 KiB
03_max_03.txt AC 19 ms 9408 KiB
03_max_04.txt AC 19 ms 9336 KiB
03_max_05.txt AC 17 ms 9332 KiB
03_max_06.txt AC 1 ms 3420 KiB
03_max_07.txt AC 1 ms 3316 KiB
03_max_08.txt AC 1 ms 3484 KiB