Contest Duration: ~ (local time) (150 minutes) Back to Home

Submission #3786048

Source Code Expand

Copy
#include<cstdio>
#include<algorithm>

class Solution{
private :
static const int maxn = 5e5 + 7;
static const int maxm = 5e5;
static const int mod = 998244353;

int n, m, frac[maxn * 2], invf[maxn * 2], ans, tot, sum;

void Init(int x) {
frac[0] = 1;
for (register int i = 1; i <= x; i++) {
frac[i] = 1ll * frac[i - 1] * i % mod;
}
invf[x] = Kasumi(frac[x], mod - 2);
for (register int i = x - 1; i >= 0; i--) {
invf[i] = 1ll * invf[i + 1] * (i + 1) % mod;
}
}

int Kasumi(int a, int b) {
int res = 1, base = a;
for (; b; b >>= 1) {
if (b & 1) {
res = 1ll * res * base % mod;
}
base = 1ll * base * base % mod;
}
return res;
}

int Inv(int x) {
return Kasumi(x, mod - 2);
}

int A(int n, int m) {
if (n == m || !m) {
return frac[n];
}
return 1ll * frac[n] * invf[m] % mod;
}

int C(int n, int m) {
if (n == m || !m) {
return 1;
}
return 1ll * A(n, m) * invf[n - m] % mod;
}

public :
Solution() {
Get();
Solve();
}

void Get() {
scanf("%d %d", &n, &m);
}

void Solve() {
Init(n + m);
if (n > m) {
std :: swap(n, m);
}
for (register int i = 1; i <= n; i++) {
tot += 1ll * C(2 * i, i) * C(n - i + m - i, n - i) % mod;
if (tot >= mod) {
tot -= mod;
}
}
sum = C(n + m, n);
printf("%lld\n", (1ll * tot * Inv(sum) % mod * Inv(2) + m) % mod);
}
};
Solution sol;

int main() {}

#### Submission Info

Submission Time 2018-12-14 14:43:31+0900 F - Yes or No luogu_bot2 C++ (GCC 5.4.1) 2000 1483 Byte AC 23 ms 7936 KB

#### Compile Error

./Main.cpp: In member function ‘void Solution::Get()’:
./Main.cpp:59:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
^

#### Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
Case Name Status Exec Time Memory
sample_01.txt 1 ms 2176 KB
sample_02.txt 1 ms 2176 KB
sample_03.txt 1 ms 2176 KB
sample_04.txt 1 ms 2176 KB
sample_05.txt 1 ms 2176 KB