QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#821284 | #9879. ReTravel | IllusionaryDominance# | WA | 1ms | 5572kb | C++20 | 1.5kb | 2024-12-19 14:56:57 | 2024-12-19 14:56:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
const ll MOD = 998244353;
ll fact[N << 1], ifact[N << 1];
ll C(int n, int m) {if(n < 0 || m < 0) return 0; return fact[n] * ifact[m] % MOD * ifact[n - m] % MOD;}
ll pow(ll x, ll y) {
ll re = 1;
for (; y; y >>= 1) {
if(y & 1) re = re * x % MOD;
x = x * x % MOD;
}
return re;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
vector<int> A(n + 10);
for (int i = 1; i <= n; ++ i) cin >> A[i];
fact[0] = 1;
for (int i = 1; i <= 2 * n; ++ i) fact[i] = fact[i - 1] * i % MOD;
ifact[2 * n] = pow(fact[2 * n], MOD - 2);
for (int i = 2 * n - 1; ~i; -- i) ifact[i] = ifact[i + 1] * (i + 1) % MOD;
ll ans = 1;
int lst3 = n, lst_con_1 = n + 1;
while(lst3 && A[lst3] != 3) -- lst3;
while(lst_con_1 && A[lst_con_1 - 1] == 1) -- lst_con_1;
if(n - lst_con_1 + 1 >= 2) ans = 0;
if(lst3 == 0 && lst_con_1 == n + 1) ans = n + 1;
for (int i = 1; i < lst_con_1; ++ i) {
if(A[i] == 1) ans = 0;
if(A[i] == 3) {
int tot = 1;
while(A[i + 1] == 3) ++ tot, ++ i;
if(i == lst3 && lst_con_1 == n + 1) (ans *= (C(2 * tot, tot) - C(2 * tot, tot - 2) + MOD) * (n - lst3) % MOD + (C(2 * tot + n - lst3, tot) - C(2 * tot + n - lst3, tot - 2) + MOD)) %= MOD;
else (ans *= C(2 * tot, tot) - C(2 * tot, tot - 2) + MOD) %= MOD;
}
}
cout << ans;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5572kb
input:
2 3 3 1 2
output:
5
result:
wrong answer 1st words differ - expected: '6', found: '5'