QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#617775#7875. Queue SortingjieloscWA 21ms6572kbC++201.3kb2024-10-06 17:03:272024-10-06 17:03:28

Judging History

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

  • [2024-10-06 17:03:28]
  • 评测
  • 测评结果:WA
  • 用时:21ms
  • 内存:6572kb
  • [2024-10-06 17:03:27]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long

using std::cin;
using std::cout;
const char endl = '\n';

const int p = 998244353;

const int N = 506;
std::vector<int> a;
int sum[N];
int f[N][N];
int C[N][N] = {1};

void solve() {
  for (int i = 1; i < N; ++i) {
    C[i][0] = 1;
    for (int j = 1; j < N; ++j) {
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % p;
    }
  }
  a.push_back(0);
  int n;
  std::cin >> n;
  for (int i = 1, x; i <= n; ++i) {
    cin >> x;
    if (x) a.push_back(x);
  }
  n = a.size() - 1;
  for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[i];
  for (int i = 1; i <= n; ++i) f[0][i] = f[i][n] = 1;
  for (int i = n - 1; i; --i) {
    if (a[i] == 0) continue;
    for (int j = 1; j <= sum[n] - sum[i - 1]; ++j) {
      if (n - j >= sum[i]) f[j][i] = (f[j][i] + f[j][i + 1]) % p;
      for (int l = 0; l <= std::min(j, sum[n] - sum[i]); ++l) {
        for (int k = std::max((int)0, sum[i] - (n - j + 1));
             k <= std::min(a[i] - 1, j - l - 1);
             ++k) {
          f[j][i] = (f[j][i] + f[l][i + 1] * C[j - l - 1][k] % p) % p;
        }
      }
    }
  }
  cout << f[n][1] << std::endl;
}

int32_t main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  solve();
#ifdef _DEBUG
  system("pause");
#endif
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 1 1 1

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: -100
Wrong Answer
time: 21ms
memory: 6572kb

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:

789222984

result:

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