提出 #58780151
ソースコード 拡げる
#include <bits/stdc++.h>
#define cerr cout << "in " << __LINE__ << "\t: "
using namespace std;
const int mod = 998244353;
struct mint {
int x;
mint() : x(0) {}
mint(long long y, bool flag = 0) {
if (flag) x = y;
else x = (y % mod + mod) % mod;
}
friend const mint ksm(mint a, long long b);
const mint inv() {return ksm(*this, mod - 2);}
};
bool operator == (const mint a, const mint b) {return a.x == b.x;}
bool operator != (const mint a, const mint b) {return a.x != b.x;}
bool operator < (const mint a, const mint b) {return a.x < b.x;}
int operator ! (const mint a) {return !a.x;}
const mint operator + (const mint a, const mint b) {
mint res(a.x + b.x, 1);
if (res.x >= mod) res.x -= mod;
return res;
}
mint& operator += (mint &a, const mint b) {
a.x += b.x;
if (a.x >= mod) a.x -= mod;
return a;
}
const mint operator - (const mint a, const mint b) {
mint res(a.x - b.x, 1);
if (res.x < 0) res.x += mod;
return res;
}
mint& operator -= (mint &a, const mint b) {
a.x -= b.x;
if (a.x < 0) a.x += mod;
return a;
}
const mint operator * (const mint a, const mint b) {
return mint((long long)a.x * b.x % mod, 1);
}
mint& operator *= (mint &a, const mint b) {
a.x = (long long)a.x * b.x % mod;
return a;
}
const mint ksm(mint a, long long b) {
mint res(1, 1);
for (; b; a *= a, b >>= 1)
if (b & 1) res *= a;
return res;
}
const mint operator / (const mint a, const mint b) {
return a * ksm(b, mod - 2);
}
mint& operator /= (mint &a, const mint b) {
a = a * ksm(b, mod - 2);
return a;
}
ostream& operator << (ostream &out, const mint a) {
return out << a.x;
}
istream& operator >> (istream &in, mint &a) {
long long y;
in >> y, a = mint(y);
return in;
}
const int MAXV = 200000;
mint inv[MAXV + 10], jc[MAXV + 10], invjc[MAXV + 10];
struct comb_init {
comb_init() {
jc[0] = 1;
for (int i = 1; i <= MAXV; i++)
jc[i] = jc[i - 1] * i;
invjc[MAXV] = jc[MAXV].inv();
for (int i = MAXV; i > 0; i--)
invjc[i - 1] = invjc[i] * i;
for (int i = 1; i <= MAXV; i++)
inv[i] = jc[i - 1] * invjc[i];
}
} comb_init;
mint C(int x, int y) {
if (y < 0 || x < y) return 0;
return jc[x] * invjc[y] * invjc[x - y];
}
#define int long long
int n, m;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
mint x = m * 2 - 1, ans = 0;
for (int i = 1; i <= n; i++) {
mint coef = (i % 2 ? 1 : -1) * C(n, i);
mint q = mint(i) / n;
mint y = 1 + (1 / q - 1) * (1 + x);
// cout << i << " " << y << "\n";
ans += coef * (y * m + m * (m - 1));
}
cout << ans << "\n";
return 0;
}
提出情報
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
800 / 800 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt, 00_sample_01.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_random_max_00.txt, 02_random_max_01.txt, 02_random_max_02.txt, 02_random_max_03.txt, 02_random_max_04.txt, 02_random_max_05.txt, 02_random_max_06.txt, 02_random_max_07.txt, 02_random_max_08.txt, 02_random_max_09.txt, 03_min_00.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
AC |
4 ms |
5816 KiB |
| 00_sample_01.txt |
AC |
39 ms |
5692 KiB |
| 01_random_00.txt |
AC |
18 ms |
5740 KiB |
| 01_random_01.txt |
AC |
31 ms |
5800 KiB |
| 01_random_02.txt |
AC |
48 ms |
5764 KiB |
| 01_random_03.txt |
AC |
39 ms |
5812 KiB |
| 01_random_04.txt |
AC |
6 ms |
5868 KiB |
| 01_random_05.txt |
AC |
45 ms |
5872 KiB |
| 01_random_06.txt |
AC |
36 ms |
5792 KiB |
| 01_random_07.txt |
AC |
13 ms |
5872 KiB |
| 01_random_08.txt |
AC |
10 ms |
5740 KiB |
| 01_random_09.txt |
AC |
24 ms |
5872 KiB |
| 02_random_max_00.txt |
AC |
59 ms |
5760 KiB |
| 02_random_max_01.txt |
AC |
59 ms |
5808 KiB |
| 02_random_max_02.txt |
AC |
58 ms |
5868 KiB |
| 02_random_max_03.txt |
AC |
58 ms |
5760 KiB |
| 02_random_max_04.txt |
AC |
58 ms |
5736 KiB |
| 02_random_max_05.txt |
AC |
58 ms |
5804 KiB |
| 02_random_max_06.txt |
AC |
58 ms |
5804 KiB |
| 02_random_max_07.txt |
AC |
58 ms |
5676 KiB |
| 02_random_max_08.txt |
AC |
59 ms |
5804 KiB |
| 02_random_max_09.txt |
AC |
59 ms |
5676 KiB |
| 03_min_00.txt |
AC |
4 ms |
5672 KiB |