QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#779315 | #9486. Random Mex | Max_s_xaM | ML | 0ms | 0kb | C++17 | 3.1kb | 2024-11-24 18:21:15 | 2024-11-24 18:21:15 |
answer
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <random>
#include <ctime>
#include <chrono>
#include <iomanip>
#include <cassert>
typedef long long ll;
typedef double lf;
// #define DEBUG 1
struct IO
{
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
#endif
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
#define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
template <typename T>
void Read(T &x)
{
#if DEBUG
std::cin >> x;
#else
bool sign = 0; char ch = gc(); x = 0;
for (; !isdigit(ch); ch = gc())
if (ch == '-') sign = 1;
for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
if (sign) x = -x;
#endif
}
void Read(char *s)
{
#if DEBUG
std::cin >> s;
#else
char ch = gc();
for (; blank(ch); ch = gc());
for (; !blank(ch); ch = gc()) *s++ = ch;
*s = 0;
#endif
}
void Read(char &c) {for (c = gc(); blank(c); c = gc());}
void Push(const char &c)
{
#if DEBUG
putchar(c);
#else
if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
*pp++ = c;
#endif
}
template <typename T>
void Write(T x)
{
if (x < 0) x = -x, Push('-');
static T sta[35];
int top = 0;
do sta[top++] = x % 10, x /= 10; while (x);
while (top) Push(sta[--top] ^ 48);
}
template <typename T>
void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)
using namespace std;
const int MAXN = 8010, mod = 998244353;
ll s[MAXN][MAXN], pw[MAXN][MAXN], ipw[MAXN][MAXN], fac[MAXN];
int main()
{
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
fac[0] = 1; for (int i = 1; i < MAXN; i++) fac[i] = fac[i - 1] * i % mod;
for (int i = 1; i < MAXN; i++) s[i][1] = 1;
for (int i = 2; i < MAXN; i++)
for (int j = 2; j <= i; j++)
s[i][j] = (s[i - 1][j - 1] + j * s[i - 1][j]) % mod;
for (int i = 1; i < MAXN; i++) pw[i][0] = 1, pw[i][1] = i, ipw[i][0] = 1;
ipw[1][1] = 1; for (int i = 2; i < MAXN; i++) ipw[i][1] = (mod - mod / i) * ipw[mod % i][1] % mod;
for (int i = 1; i < MAXN; i++)
for (int j = 2; j < MAXN; j++)
pw[i][j] = pw[i][j - 1] * pw[i][1] % mod, ipw[i][j] = ipw[i][j - 1] * ipw[i][1] % mod;
int T;
Read(T);
while (T--)
{
int n, m;
Read(n), Read(m);
cout << ((pw[m + 1][n] - s[n][m + 1] * fac[m + 1] % mod + mod) * ipw[m][n] - 1 + mod) % mod << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
4 3 2 1 1 20 23 8000 8000
output:
374341634 1 111675632 994279778