QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#273794#7875. Queue Sortingucup-team992#AC ✓357ms34508kbC++172.0kb2023-12-03 04:12:062023-12-03 04:12:07

Judging History

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

  • [2023-12-03 04:12:07]
  • 评测
  • 测评结果:AC
  • 用时:357ms
  • 内存:34508kb
  • [2023-12-03 04:12:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ll long long
typedef int uci;
#define int long long
#define F first
#define S second
#define ar array

const ll MOD = 998244353;
vector<ll> FACTS(1000);

ll modexp(ll n, ll p) {
    ll r = 1;
    ll m = n;
    while(p) {
        if(p&1) r = (r*m)%MOD;
        m = (m*m)%MOD;
        p >>= 1;
    }
    return r;
}

ll modinv(ll n) {
    return modexp(n, MOD-2);
}


ll NCK(ll n, ll k) {
    ll re = FACTS[n];
    re = (re*modinv(FACTS[k]))%MOD;
    re = (re*modinv(FACTS[n-k]))%MOD;
    return re;
}


void solve(){
    FACTS[0] = 1;
    for(ll i = 1; i < FACTS.size(); i++)
        FACTS[i] = FACTS[i-1]*i % MOD;

    vector<vector<ll>> NCKS(1001, vector<ll>(2001));
    for(ll i = 0; i < NCKS.size(); i++) {
        NCKS[i][0] = 1;
        for(ll j = 1; j <= i; j++) {
            NCKS[i][j] = (NCKS[i][j-1] + NCK(i, j)) % MOD;
        }
    }

    ll N; cin >> N;
    vector<ll> A(N);
    for(ll i = 0; i < N; i++) cin >> A[i];

    vector<vector<ll>> DP(1000, vector<ll>(2000));
    DP[0][0] = 1;
    for(ll a = 1; a <= N; a++) {
        for(ll nbp = 0; nbp <= 500; nbp++) {
            for(ll d = -nbp; d <= A[a-1]; d++) {
                ll max_placed = min(nbp, A[a-1] - 1 - d);

                if(d == A[a-1]) {
                    (DP[a][nbp + d] += DP[a-1][nbp]) %= MOD;
                } else {
                    ll mi_placed = max(0ll, -d);
                    ll m = NCKS[A[a-1]-d-1][max_placed];
                    if(mi_placed > 0) (m += MOD - NCKS[A[a-1]-d-1][mi_placed-1]) %= MOD;
                    (DP[a][nbp + d] += DP[a-1][nbp] * m) %= MOD;
                }

            }
        }
    }

    /*for(ll a = 1; a <= N; a++) {
        for(ll nbp = 0; nbp <= 500; nbp++) {
            if(DP[a][nbp] > 0)
                cout << a << " " << nbp << " " << DP[a][nbp] << endl;
        }
    }*/
    cout << DP[N][0] << endl;
}

uci main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 103ms
memory: 34508kb

input:

4
1 1 1 1

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: 0
Accepted
time: 254ms
memory: 34468kb

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:

507010274

result:

ok 1 number(s): "507010274"

Test #3:

score: 0
Accepted
time: 357ms
memory: 34452kb

input:

500
1 1 0 2 1 0 2 3 2 0 0 2 0 2 1 1 0 0 1 1 1 2 1 1 1 0 1 1 2 2 1 4 0 2 1 0 2 3 1 0 1 1 0 2 1 2 2 1 0 0 3 1 4 1 1 2 1 1 0 1 3 1 2 0 0 0 2 1 2 0 0 3 2 1 1 1 1 1 2 1 0 1 0 0 0 1 0 0 2 1 1 0 1 0 1 0 1 0 0 1 0 1 1 0 0 0 1 0 0 0 2 1 1 0 1 1 0 1 1 0 0 1 0 3 1 3 0 0 2 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 1 2 0 0 ...

output:

7590964

result:

ok 1 number(s): "7590964"

Test #4:

score: 0
Accepted
time: 214ms
memory: 34500kb

input:

200
3 1 0 3 2 1 0 3 1 1 2 3 3 1 6 2 1 3 2 1 1 2 1 2 1 5 2 2 3 4 0 4 2 1 2 2 0 2 3 1 2 3 6 3 2 3 2 2 4 2 7 2 1 5 1 9 0 4 4 8 3 3 3 1 3 0 2 2 8 1 3 5 4 3 0 6 1 6 1 3 4 2 2 1 1 4 4 4 1 0 4 3 4 3 3 0 3 2 0 0 3 4 0 3 1 3 2 4 3 2 0 3 2 2 3 2 2 2 1 2 2 1 0 2 0 3 1 3 5 1 3 3 6 5 3 2 2 2 3 6 2 0 5 2 2 2 2 1 ...

output:

507844569

result:

ok 1 number(s): "507844569"

Test #5:

score: 0
Accepted
time: 156ms
memory: 34444kb

input:

100
4 8 2 5 4 4 3 0 2 7 2 3 4 4 1 2 3 4 4 4 3 3 3 3 3 2 4 1 3 5 5 1 4 6 1 1 1 3 2 3 2 1 0 1 4 4 2 4 2 5 3 5 1 6 2 3 3 1 4 4 4 1 4 4 3 4 2 0 2 3 6 1 3 3 5 4 1 1 2 3 0 3 2 2 1 3 3 2 5 6 3 2 3 3 5 4 2 3 4 4

output:

989550242

result:

ok 1 number(s): "989550242"

Test #6:

score: 0
Accepted
time: 110ms
memory: 34484kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 355ms
memory: 34468kb

input:

500
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

1

result:

ok 1 number(s): "1"

Test #8:

score: 0
Accepted
time: 115ms
memory: 34468kb

input:

10
2 1 3 3 2 3 1 1 3 1

output:

165452340

result:

ok 1 number(s): "165452340"

Test #9:

score: 0
Accepted
time: 123ms
memory: 34448kb

input:

20
0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0

output:

2

result:

ok 1 number(s): "2"

Test #10:

score: 0
Accepted
time: 123ms
memory: 34408kb

input:

20
0 0 1 0 0 0 0 1 0 0 0 0 0 0 2 0 1 0 0 0

output:

28

result:

ok 1 number(s): "28"

Test #11:

score: 0
Accepted
time: 114ms
memory: 34404kb

input:

10
1 1 1 1 1 1 1 1 1 1

output:

16796

result:

ok 1 number(s): "16796"

Test #12:

score: 0
Accepted
time: 254ms
memory: 34432kb

input:

300
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

431279497

result:

ok 1 number(s): "431279497"

Test #13:

score: 0
Accepted
time: 120ms
memory: 34436kb

input:

2
232 268

output:

929717758

result:

ok 1 number(s): "929717758"

Test #14:

score: 0
Accepted
time: 108ms
memory: 34432kb

input:

1
500

output:

1

result:

ok 1 number(s): "1"

Test #15:

score: 0
Accepted
time: 108ms
memory: 34500kb

input:

3
155 180 165

output:

911108550

result:

ok 1 number(s): "911108550"

Extra Test:

score: 0
Extra Test Passed