Submission #46192547


Source Code Expand

#include<bits/stdc++.h>
#define LL long long
#define DB double
#define MOD 998244353
#define ls(x) x << 1
#define rs(x) x << 1 | 1
#define lowbit(x) x & (-x)
#define PII pair<int, int>
#define MP make_pair
#define VI vector<int>
#define VII vector<int>::iterator
#define all(x) x.begin(), x.end()
#define EB emplace_back
#define SI set<int>
#define SII set<int>::iterator
#define QI queue<int>
using namespace std;
template<typename T> void chkmn(T &a, const T &b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T &b) { (a < b) && (a = b); }
int inc(const int &a, const int &b) { return a + b >= MOD ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return a - b < 0 ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
int sqr(const int &a) { return 1LL * a * a % MOD; }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
    int res = 1;
    while(k)
    {
        if(k & 1) Mul(res, x);
        Sqr(x), k >>= 1;
    }
    return res;
}
const int N = 8e5 + 5;
int fac[N], facinv[N];
void preprocess()
{
	fac[0] = facinv[0] = 1;
	for(int i = 1; i < N; ++i)
		fac[i] = mul(fac[i - 1], i);
	facinv[N - 1] = qwqmi(fac[N - 1]);
	for(int i = N - 2; i >= 1; --i)
		facinv[i] = mul(facinv[i + 1], i + 1);
}
int C(int n, int m)
{
	if(n < m || n < 0 || m < 0) return 0;
	return mul(fac[n], mul(facinv[m], facinv[n - m]));
}
int n, m, ans = 0;
int calc1(int x, int y)
{
	if(x < 1 || x > n || y < 1 || y > m) return 0;
	int w = 1;
	Mul(w, C(x - 1 + y - 1, x - 1));
	Mul(w, C(n - x + y - 1, n - x));
	Mul(w, C(x - 1 + y - 1 + n - x + y - 1, x - 1 + y - 1));
	return w;
}
int calc2(int x, int y)
{
	if(x < 1 || x > n || y < 1 || y > m) return 0;
	int w = 1;
	Mul(w, C(x - 1 + m - y, x - 1));
	Mul(w, C(n - x + m - y, n - x));
	Mul(w, C(x - 1 + m - y + n - x + m - y, x - 1 + m - y));
	return w;
}
int Catalan(int x)
{
	if(x < 0) return 0;
	if(x == 0) return 1;
	return dec(C(2 * x, x), C(2 * x, x + 1));
}
int main()
{
	preprocess();
	scanf("%d %d", &n, &m);
	for(int x = 1; x <= n; ++x)
		for(int y = 1; y <= m; ++y)
		{
			int w1 = calc1(x, y);
			for(int i = 1; i < y; ++i)
				Dec(w1, mul(calc1(x, i), mul(2, Catalan(y - i - 1))));
			int w2 = calc2(x, y);
			for(int i = y + 1; i <= m; ++i)
				Dec(w2, mul(calc2(x, i), mul(2, Catalan(i - y - 1))));
//			printf("%d %d %d %d\n", x, y, w1, w2);
			Inc(ans, mul(w1, w2));
		}
	printf("%d\n", ans);
    return 0;
}

Submission Info

Submission Time
Task F - Chance Meeting
User Schucking_Sattin
Language C++ 20 (gcc 12.2)
Score 0
Code Size 2744 Byte
Status TLE
Exec Time 2211 ms
Memory 9936 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:82:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   82 |         scanf("%d %d", &n, &m);
      |         ~~~~~^~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 900
Status
AC × 1
TLE × 1
AC × 4
TLE × 38
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
random_01.txt AC 1526 ms 9932 KiB
random_02.txt TLE 2208 ms 9660 KiB
random_03.txt TLE 2208 ms 9596 KiB
random_04.txt TLE 2208 ms 9628 KiB
random_05.txt AC 25 ms 9924 KiB
random_06.txt AC 21 ms 9884 KiB
random_07.txt TLE 2208 ms 9632 KiB
random_08.txt TLE 2208 ms 9628 KiB
random_09.txt TLE 2208 ms 9584 KiB
random_10.txt TLE 2208 ms 9600 KiB
random_11.txt TLE 2208 ms 9660 KiB
random_12.txt TLE 2208 ms 9612 KiB
random_13.txt TLE 2208 ms 9612 KiB
random_14.txt TLE 2208 ms 9640 KiB
random_15.txt TLE 2208 ms 9708 KiB
random_16.txt TLE 2207 ms 9596 KiB
random_17.txt TLE 2208 ms 9608 KiB
random_18.txt TLE 2211 ms 9472 KiB
random_19.txt TLE 2210 ms 9620 KiB
random_20.txt TLE 2208 ms 9564 KiB
random_21.txt TLE 2207 ms 9608 KiB
random_22.txt TLE 2208 ms 9660 KiB
random_23.txt TLE 2210 ms 9612 KiB
random_24.txt TLE 2208 ms 9632 KiB
random_25.txt TLE 2206 ms 9604 KiB
random_26.txt TLE 2208 ms 9472 KiB
random_27.txt TLE 2208 ms 9588 KiB
random_28.txt TLE 2208 ms 9596 KiB
random_29.txt TLE 2208 ms 9712 KiB
random_30.txt TLE 2208 ms 9592 KiB
random_31.txt TLE 2207 ms 9656 KiB
random_32.txt TLE 2207 ms 9616 KiB
random_33.txt TLE 2208 ms 9568 KiB
random_34.txt TLE 2208 ms 9660 KiB
random_35.txt TLE 2208 ms 9608 KiB
random_36.txt TLE 2208 ms 9592 KiB
random_37.txt TLE 2208 ms 9612 KiB
random_38.txt TLE 2210 ms 9600 KiB
random_39.txt TLE 2208 ms 9608 KiB
random_40.txt TLE 2208 ms 9616 KiB
sample_01.txt AC 10 ms 9936 KiB
sample_02.txt TLE 2211 ms 9620 KiB