Cod sursa(job #3153604)

Utilizator Traian_7109Traian Mihai Danciu Traian_7109 Data 30 septembrie 2023 13:35:31
Problema Diamant Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <bits/stdc++.h>

using namespace std;

signed main() {
  freopen("diamant.in", "r", stdin);
  freopen("diamant.out", "w", stdout);
  ios_base :: sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  const int mod = 10000;
  int n, m, x;
  cin >> n >> m >> x;
  int smax = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      smax += i * j;
  if (abs(x) > smax)
    cout << "0";
  else {
    const int add = 45000;
    vector<vector<int>> dp(2, vector<int>(add + add + 1));
    dp[1][add] = 1;
    smax = 0;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        for (int k = -smax; k <= smax; k++) {
          dp[0][k + add + i * j] = (dp[0][k + add + i * j] + dp[1][k + add]) % mod;
          dp[0][k + add - i * j] = (dp[0][k + add - i * j] + dp[1][k + add]) % mod;
          dp[0][k + add] = (dp[0][k + add] + dp[1][k + add]) % mod;
        }
        smax += i * j;
        for (int k = -smax; k <= smax; k++) {
          dp[1][k + add] = dp[0][k + add];
          dp[0][k + add] = 0;
        }
      }
    cout << dp[1][x + add];
  }
  #warning cam simplu pt oni xi-xii sau cat o fi
  return 0;
}