QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#145328#6410. Classical DP ProblemInsert_Username_HereWA 1ms3460kbC++201.1kb2023-08-22 07:30:192023-08-22 07:30:20

Judging History

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

  • [2023-08-22 07:30:20]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3460kb
  • [2023-08-22 07:30:19]
  • 提交

answer

#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
using namespace std;
typedef long long ll;
const ll mod = 998244353;
// Cope Counter = at least 109

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
  ll n;
  cin >> n;
  ll arr[n + 1][2], dp[n][n];
  ll smax = 0, c = 1;
  arr[0][0] = arr[0][1] = 0;
  for(ll i = n; i > 0; i--) {
    cin >> arr[i][0];
    for(; c <= arr[i][0]; c++) arr[c][1] = i;
    smax = max(smax, min(i + 1, arr[i][0]));
  }
  for(ll i = 0; i < n; i++) {
    for(ll j = 0; j < n; j++) dp[i][j] = 0;
  }
  dp[0][0] = 1;
  ll fact = 1, ans = 0;
  for(ll i = 2; i <= smax; i++) fact = fact * i % mod;
  if(smax == n) {
    cout << fact << "\n";
    return 0;
  }
  for(ll bk = 0; bk < 2; bk++) {
    for(ll i = 1; i <= smax; i++) {
      for(ll j = 1; j <= i; j++) {
        dp[i][j] = dp[i - 1][j] + arr[i][bk] - arr[smax + 1][bk] + j;
        dp[i][j] += dp[i - 1][j - 1] + arr[smax + 1][bk] - j - 1;
        dp[i][j] %= mod;
      }
    }
    ans = (ans + dp[smax][arr[smax][bk]]) % mod;
  }
  cout << smax << " " << (ans - fact + mod) % mod << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3420kb

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3460kb

input:

1
1

output:

1

result:

wrong answer Answer contains longer sequence [length = 2], but output contains 1 elements