QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#355406#7875. Queue SortingBUET_POTATOES#WA 42ms8764kbC++201.4kb2024-03-16 17:20:062024-03-16 17:20:06

Judging History

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

  • [2024-03-16 17:20:06]
  • 评测
  • 测评结果:WA
  • 用时:42ms
  • 内存:8764kb
  • [2024-03-16 17:20:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
const int MOD = 998244353;
int C[N][N];
int add(int a, int b){
    a += b;
    if(a >= MOD)a -= MOD;
    return a;
}
int mul(int a, int b){
    return (long long)a * b % MOD;
}
int A[N];
int dp[N][N];
void solv(int ces){
    C[0][0] = 1;
    for(int i = 1; i < N; i++){
        C[i][0] = 1;
        for(int j = 1; j < N; ++j){
            C[i][j] = add(C[i - 1][j], C[i - 1][j - 1]);
        }
    }


    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> A[i];
    }


    for(int i = 0; i <= n; i++)dp[n + 1][i] = 1;

    for(int i = n; i > 0; i--){
        for(int j = 0; j <= n; j++){
            dp[i][j] = dp[i + 1][j + A[i]];
            for(int k = 1; k <= A[i]; k++){
                for(int l = 1; l <= j; l++){
                    dp[i][j] = add(dp[i][j], mul(dp[i + 1][l + A[i] - k], C[j - l + k - 1][k - 1]));
                }
            }
        }
    }

//    for(int i = 0; i <= n; i++){
//        for(int j = 0; j <= n; j++){
//            cout << dp[i][j] << ' ';
//        }
//        cout << endl;
//    }


    cout << dp[1][0] << "\n";


}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int tc = 1;
//    cin>>tc;
    for(int ces=1; ces<=tc; ces++){
        solv(ces);
    }

    return 0;
}




Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 1 1 1

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: -100
Wrong Answer
time: 42ms
memory: 8764kb

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:

511879815

result:

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