| 比赛 |
期末考试3 |
评测结果 |
AAAATTRRERERRMTEREMM |
| 题目名称 |
hope I can sort |
最终得分 |
20 |
| 用户昵称 |
梦那边的美好BP |
运行时间 |
5.775 s |
| 代码语言 |
C++ |
内存使用 |
80.47 MiB |
| 提交时间 |
2026-02-11 11:17:51 |
显示代码纯文本
#include <ctime>
#include <iostream>
#include <random>
#include <vector>
using namespace std;
const int mod = 998244353;
typedef long long ll;
ll n, m, cnt = 0, ans = 0;
int a[5003];
bool ch() {
for (int i = 1; i < n; i++) {
if (a[i] > a[i + 1]) return 0;
}
return 1;
}
void dfs(int t) {
if (t == m + 1) {
cnt++;
if (ch()) ans++;
return;
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (a[i] > a[j]) {
swap(a[i], a[j]);
dfs(t + 1);
swap(a[i], a[j]);
} else {
dfs(t + 1);
}
}
}
}
ll ksm(ll x, ll y) {
ll ans = 1;
while (y) {
if (y & 1) {
ans *= x;
ans %= mod;
}
y >>= 1;
x *= x;
x %= mod;
}
return ans;
}
int main() {
freopen("hopeicansort.in", "r", stdin);
cin >> n >> m;
if (n > 10) {
mt19937 rng(std::random_device{}());
uniform_int_distribution<int> dist(1, 4);
int x = dist(rng);
if (x == 1) {
freopen("hopeicansort.out", "w", stdout);
return -1;
}
if (x == 2) {
freopen("hopeicansort.out", "w", stdout);
vector<long long> v;
for (long long i = 1; i <= 1e8; i++) v.push_back(i);
return 0;
}
if (x == 3) {
freopen("hopeicansort.out", "w", stdout);
while (1) cout << 1;
return 0;
}
if (x == 4) {
return 0;
}
}
freopen("hopeicansort.out", "w", stdout);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
dfs(1);
// cout << cnt << " " << ans << endl;
cout << (ans * ksm(cnt, mod - 2)) % mod;
return 0;
}