QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#168679#6410. Classical DP ProblemrealIyxiangCompile Error//C++141.4kb2023-09-08 19:26:452023-09-08 19:26:45

Judging History

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

  • [2023-09-08 19:26:45]
  • 评测
  • [2023-09-08 19:26:45]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define dep(i, l, r) for (int i = r; i >= l; --i)
const int N = 5e3 + 5;
const int P = 998244353; 
int n, r, c, ans, a[N], b[N], fac[N], inv[N], f[N][N]; 

int inc (int a, int b) { return (a += b) >= P ? a - P : a; }
int dec (int a, int b) { return (a -= b) < 0 ? a + P : a; }
int mul (int a, int b) { return 1ll * a * b % P; }
int fpow (int a, int b) { int ans = 1; for ( ; b; a = mul(a, a), b >>= 1) if(b & 1) ans = mul(ans, a); return ans; }
void init (int n) {
  fac[0] = inv[0] = 1;
  rep(i, 1, n) fac[i] = mul(fac[i - 1], i), inv[i] = fpow(fac[i], P - 2); 
}
int calc () {
  rep(i, 1, n) if(a[i] >= i) r = i; 
  c = a[r + 1]; 
  memset(f, 0, sizeof(f)); 
  f[0][0] = 1;
  rep(i, 1, r) rep(j, 0, min(i, c)) {
    f[i][j] = mul(f[i - 1][j], a[i] - (c - j)); 
    if(j) f[i][j] = inc(f[i][j], mul(f[i - 1][j - 1], c - j + 1)); 
  }
  return f[r][c]; 
}

int main () {
  ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0); 
  cin >> n, init(n); 
  rep(i, 1, n) cin >> a[i]; 
  reverse(a + 1, a + n + 1); 
  ans = inc(ans, calc()); 
  rep(i, 1, n) ++b[a[i]]; 
  dep(i, 1, n) b[i] += b[i + 1], a[i] = b[i]; 
  ans = inc(ans, calc()); 
  ans = dec(ans, fac[r]); 
  cout << r << ' ' << ans << '\n'; 
  return 0; 
}

詳細信息

answer.code: In function ‘int calc()’:
answer.code:22:3: error: ‘memset’ was not declared in this scope
   22 |   memset(f, 0, sizeof(f));
      |   ^~~~~~
answer.code:4:1: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
    3 | #include <algorithm>
  +++ |+#include <cstring>
    4 | using namespace std;