fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. const int MOD = 998244353;
  7.  
  8. void solve(){
  9. int n;
  10. cin >> n;
  11. vector<int> a(n);
  12. int sum = 0;
  13.  
  14. for(int i = 0; i < n; i++){
  15. cin >> a[i];
  16. sum += a[i];
  17. }
  18.  
  19. sort(a.rbegin(), a.rend());
  20.  
  21. ll ans = 0;
  22. int dp1[sum + 1], dp2[sum + 1];
  23. memset(dp1, 0, sizeof dp1);
  24. memset(dp2, 0, sizeof dp2);
  25. dp1[0] = 1;
  26.  
  27. for(int i = 0; i < n; i++){
  28. int tmp1[sum + 1];
  29. int tmp2[sum + 1];
  30. memset(tmp1, 0, sizeof tmp1);
  31. memset(tmp2, 0, sizeof tmp2);
  32.  
  33. for(int j = 0; j <= sum; j++){
  34. int rem = max(a[i] - j, j - a[i]);
  35. tmp1[rem] += dp2[j] + dp1[j] * rem;
  36. tmp1[rem] %= MOD;
  37. tmp2[rem] += dp1[j];
  38. tmp2[rem] %= MOD;
  39. }
  40.  
  41. for(int j = 0; j <= sum; j++){
  42. dp1[j] += tmp2[j];
  43. dp1[j] %= MOD;
  44. dp2[j] += tmp1[j];
  45. dp2[j] %= MOD;
  46. }
  47.  
  48. }
  49. cout << dp1[2] << "\n";
  50.  
  51. for(int i = 0; i <= sum; i++){
  52. cout << dp2[i] << " ";
  53. ans += dp2[i];
  54. ans %= MOD;
  55. }
  56. cout << "\n";
  57. cout << ans << "\n";
  58. }
  59.  
  60. int main(){
  61. ios_base::sync_with_stdio(false);
  62. cin.tie(nullptr);
  63.  
  64. int t = 1;
  65. // cin >> t;
  66.  
  67. for(int i = 1; i <= t; i++){
  68. solve();
  69. }
  70. return 0;
  71. }
Success #stdin #stdout 0.01s 5280KB
stdin
3
1 1 2
stdout
1
4 8 2 0 0 
14