| 比赛 |
期末考试3 |
评测结果 |
AAAAMMMMMMMMMMMMMMMM |
| 题目名称 |
hope I can sort |
最终得分 |
20 |
| 用户昵称 |
LikableP |
运行时间 |
10.297 s |
| 代码语言 |
C++ |
内存使用 |
801.67 MiB |
| 提交时间 |
2026-02-11 10:36:36 |
显示代码纯文本
#include <cstdio>
#include <cctype>
struct IO {
static const int BUFSIZE = 1 << 20;
char buf[BUFSIZE], *p1, *p2;
char pbuf[BUFSIZE], *pp;
IO() : p1(buf), p2(buf), pp(pbuf) {};
~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); }
char getchar() {
if (p1 == p2) {
p2 = (p1 = buf) + fread(buf, 1, BUFSIZE, stdin);
if (p1 == p2) return EOF;
}
return *p1++;
}
void putchar(char ch) {
if (pp - pbuf == BUFSIZE) fwrite(pbuf, 1, BUFSIZE, stdout), pp = pbuf;
*pp++ = ch;
}
template <typename T> T read() {
T res = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch ^ 48);
return res * f;
}
template <typename T> void write(T x, char ed = '\n') {
if (x < 0) x = -x, putchar('-');
static int sta[sizeof(T) << 2], top = 0;
do {
sta[++top] = x % 10;
x /= 10;
} while (x);
while (top) {
putchar(sta[top--] ^ 48);
}
putchar(ed);
}
} io;
#include <vector>
#include <algorithm>
typedef long long ll;
const int MAXN = 5010;
const ll MOD = 998244353;
ll kasumi(ll x, ll y) {
ll res = 1;
while (y) {
if (y & 1) res = res * x % MOD;
y >>= 1;
x = x * x % MOD;
}
return res;
}
int n, m;
std::vector<std::vector<int>> allPosibilities;
std::vector<int> arr;
void dfs(int now) {
if (now > m) {
allPosibilities.push_back(arr);
return ;
}
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (arr[i] > arr[j]) {
std::swap(arr[i], arr[j]);
dfs(now + 1);
std::swap(arr[i], arr[j]);
} else {
dfs(now + 1);
}
}
}
}
int main() {
#ifdef LOCAL
freopen("!input.in", "r", stdin);
freopen("!output.out", "w", stdout);
#else
freopen("hopeicansort.in", "r", stdin);
freopen("hopeicansort.out", "w", stdout);
#endif
n = io.read<int>(), m = io.read<int>();
for (int i = 0; i < n; ++i) {
arr.push_back(io.read<int>());
}
dfs(1);
if (allPosibilities.empty()) {
io.write(1);
return 0;
}
ll all = allPosibilities.size(), cnt = 0;
for (std::vector<int> vec : allPosibilities) {
cnt += std::is_sorted(vec.begin(), vec.end());
}
io.write(cnt * kasumi(all, MOD - 2) % MOD);
return 0;
}