QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#155838 | #3090. Inverse Problem | 5ab | RE | 0ms | 0kb | C++20 | 1.4kb | 2023-09-02 10:40:54 | 2023-09-02 10:40:55 |
answer
/* name: perm
* author: 5ab
* created at: 2023-09-02
*/
#include <iostream>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ssz(x) (int((x).size()))
auto chmax = [](auto& x, auto y) { if (x < y) x = y; };
auto chmin = [](auto& x, auto y) { if (x > y) x = y; };
using ll = long long;
const int max_n = 1e6, mod = 998244353;
int a[max_n], b[max_n];
signed main()
{
freopen("perm.in", "r", stdin);
freopen("perm.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int cas, n, m;
cas = 1;
while (cas--)
{
cin >> n >> m;
for (int i = 0; i < m; i++)
cin >> a[i], a[i]--;
fill(b, b + n, 1);
bool isp = 0;
for (int i = 1; i < m; i++)
{
if (a[i] < a[i - 1])
isp = true;
if (isp)
b[a[i]] = 0;
}
for (int i = 1; i < n; i++)
b[i] += b[i - 1];
for (int i = 0; i < n; i++)
b[i]--;
int ans = 1, cfc = 0;
if (b[a[0]] != 0)
{
cout << "0\n";
continue;
}
for (int i = 0, j = 1; i < m; i++, j++)
{
if (i > 0 && a[i] < a[i - 1])
break;
if (i == m - 1 || a[i + 1] < a[i])
cfc += 2;
else
cfc++;
while (j < (i == m - 1 ? n : b[a[i + 1]]))
ans = 1ll * ans * cfc % mod, cfc++, j++;
// cerr << cfc << " " << j << endl;
}
cout << ans << "\n";
}
return 0;
}
// started coding at: 09-02 10:20:56
詳細信息
Test #1:
score: 0
Dangerous Syscalls
input:
7 2 2 1