QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#149655#6410. Classical DP ProblemInsert_Username_HereWA 1ms3672kbC++201.1kb2023-08-25 07:27:112023-08-25 07:27:15

Judging History

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

  • [2023-08-25 07:27:15]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3672kb
  • [2023-08-25 07:27:11]
  • 提交

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 120

ll po(ll b, ll p) {
  ll a = 1;
  while(p > 0) {
    if(p % 2 == 1) a = a * b % mod;
    b = b * b % mod;
    p /= 2;
  }
  return a;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

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

input:

1
1

output:

1 0

result:

wrong answer 2nd numbers differ - expected: '1', found: '0'