QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#960005 | #3090. Inverse Problem | xiaoxia# | WA | 1ms | 3712kb | C++20 | 1.5kb | 2025-04-01 05:59:11 | 2025-04-01 05:59:14 |
Judging History
answer
#include<bits/stdc++.h>
#define int i64 /* R.I.P */
#define all(x) std::begin(x), std::end(x)
#define rall(x) std::rbegin(x), std::rend(x)
using i64 = long long;
using u64 = unsigned long long;
using ld = long double;
constexpr int M = 998244353;
/*
4 5 9 10 2 7 8 3 6 1
A 中必须有 1
5 2 8 4 6 3 7 1 10
9 7 [3 6 5 1] 2
C(10, )
2 [1 3 4 5]
7 5 4 [3 2 6 1 9]
从小到大确定可以放的位置
看数组中的第一个数,是不是恰好是数组的 mex - 1
如果不是,输出0
二分一下前缀 max
*/
void solve() {
i64 n, k;
std::cin >> k >> n;
std::vector<int> a(n);
for (auto &i : a) std::cin >> i;
auto b = a;
std::sort(all(b));
int mex = 1;
for (; mex <= n; mex++) {
if (b[mex - 1] != mex) break;
}
if (b.back() != n && mex < a[0]) {
std::cout << 0;
return;
}
i64 ans = 1;
std::set<int> c;
for (int i = 1; i <= k; i++) c.insert(i);
for (auto j : a) c.erase(j);
std::vector<int> pre(n);
pre[0] = a[0];
for (int i = 1; i < n; i++) {
pre[i] = std::max(pre[i - 1], a[i]);
}
int bonus = 0;
for (auto i : c) {
(ans *= (std::lower_bound(all(pre), i) - pre.begin()) + 1 + bonus) %= M;
bonus++;
}
std::cout << ans;
}
signed main() {
std::cin.tie(0)->sync_with_stdio(false);
int t = 1;
//std::cin >> t;
while(t--) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3712kb
input:
7 2 2 1
output:
2520
result:
wrong answer 1st lines differ - expected: '720', found: '2520'