QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#271567#7875. Queue Sortingucup-team045#WA 81ms7820kbC++203.5kb2023-12-02 13:20:542023-12-02 13:20:56

Judging History

你现在查看的是最新测评结果

  • [2023-12-02 13:20:56]
  • 评测
  • 测评结果:WA
  • 用时:81ms
  • 内存:7820kb
  • [2023-12-02 13:20:54]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
using LL = long long;
template<const int T>
struct ModInt {
    const static int mod = T;
    int x;
    ModInt(int x = 0) : x(x % mod) {}
    ModInt(long long x) : x(int(x % mod)) {} 
    int val() { return x; }
    ModInt operator + (const ModInt &a) const { int x0 = x + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
    ModInt operator - (const ModInt &a) const { int x0 = x - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
    ModInt operator * (const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }
    ModInt operator / (const ModInt &a) const { return *this * a.inv(); }
    bool operator == (const ModInt &a) const { return x == a.x; };
    bool operator != (const ModInt &a) const { return x != a.x; };
    void operator += (const ModInt &a) { x += a.x; if (x >= mod) x -= mod; }
    void operator -= (const ModInt &a) { x -= a.x; if (x < 0) x += mod; }
    void operator *= (const ModInt &a) { x = 1LL * x * a.x % mod; }
    void operator /= (const ModInt &a) { *this = *this / a; }
    friend ModInt operator + (int y, const ModInt &a){ int x0 = y + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
    friend ModInt operator - (int y, const ModInt &a){ int x0 = y - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
    friend ModInt operator * (int y, const ModInt &a){ return ModInt(1LL * y * a.x % mod);}
    friend ModInt operator / (int y, const ModInt &a){ return ModInt(y) / a;}
    friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x;}
    friend istream &operator>>(istream &is, ModInt &t){return is >> t.x;}

    ModInt pow(int64_t n) const {
        ModInt res(1), mul(x);
        while(n){
            if (n & 1) res *= mul;
            mul *= mul;
            n >>= 1;
        }
        return res;
    }
    
    ModInt inv() const {
        int a = x, b = mod, u = 1, v = 0;
        while (b) {
            int t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        if (u < 0) u += mod;
        return u;
    }
    
};
using mint = ModInt<998244353>;
mint C[1005][1005];

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    const int N = 500;
    for(int i = 0; i <= 2 * N; i++){
        for(int j = 0; j <= i; j++){
            if (!j){
                C[i][j] = 1;
            }
            else{
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
            }
        }
    }

    int n;
    cin >> n;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++) cin >> a[i];
    // 两个序列,最后一个元素靠前的序列最后一个元素位于i的方案数.
    vector<mint> dp(N + 1);
    int t = 1;
    while(a[t] == 0) t++;
    dp[0] = 1;
    int sum = a[t];
    for(int i = t + 1; i <= n; i++){
        if (!a[i]) continue;
        vector<mint> ndp(N + 1);
        for(int j = 0; j <= sum; j++){
            // k = 0
            ndp[j] += dp[j];
            // k != 0
            for(int k = 1; k <= a[i]; k++){
                for(int t = j + 1; t <= sum; t++){
                    mint cnt = C[k + t - j - 1][t - j - 1] - (t - j == 1 ? 0 : C[k + t - j - 2][t - j - 2]);
                    ndp[t] += dp[j] * cnt;
                }
            }
        }
        dp.swap(ndp);
        sum += a[i];
    }

    mint ans = 0;
    for(int i = 0; i <= N; i++) ans += dp[i];
    cout << ans << '\n';

}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 7784kb

input:

4
1 1 1 1

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: -100
Wrong Answer
time: 81ms
memory: 7820kb

input:

300
0 5 2 2 1 0 3 2 2 5 2 1 1 2 1 3 2 3 2 0 0 0 0 1 2 2 3 0 2 2 3 2 0 2 3 0 6 0 0 2 0 1 3 2 1 1 1 3 4 0 1 0 4 1 1 1 1 1 1 2 3 2 1 2 3 2 3 0 5 3 3 2 0 1 1 0 2 1 1 2 0 0 2 1 1 3 2 2 1 2 1 3 0 3 0 1 2 2 0 5 0 2 2 0 0 0 1 2 1 4 2 1 1 0 3 0 2 0 3 1 1 2 0 2 1 1 0 2 0 1 2 2 3 3 1 1 1 1 0 1 3 3 1 0 2 2 4 2 ...

output:

365511716

result:

wrong answer 1st numbers differ - expected: '507010274', found: '365511716'