QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#821284#9879. ReTravelIllusionaryDominance#WA 1ms5572kbC++201.5kb2024-12-19 14:56:572024-12-19 14:56:57

Judging History

This is the latest submission verdict.

  • [2024-12-19 14:56:57]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5572kb
  • [2024-12-19 14:56:57]
  • Submitted

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;
}

Details

Tip: Click on the bar to expand more detailed information

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'