Cod sursa(job #3376773)

Utilizator bobitzaxddCucos Bogdan bobitzaxdd Data 19 noiembrie 2026 16:32:09
Problema Diamant Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb

#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

ifstream cin("diamant.in");
ofstream cout ("diamant.out");

const int MOD = 10000;

int main() {
    freopen("diamant.in", "r", stdin);
    freopen("diamant.out", "w", stdout);

    int N, M, X;
    cin >> N >> M >> X;

    int S = (N * (N + 1) / 2) * (M * (M + 1) / 2);

    if (X < -S || X > S) {
        cout << 0;
        return 0;
    }

    int offset = S;
    vector<int> dp(2 * S + 1, 0);
    vector<int> ndp(2 * S + 1, 0);

    dp[offset] = 1;

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            int v = i * j;

            fill(ndp.begin(), ndp.end(), 0);

            for (int s = 0; s <= 2 * S; s++) {
                if (dp[s] == 0)
                    continue;

                ndp[s] = (ndp[s] + dp[s]) % MOD;

                if (s + v <= 2 * S)
                    ndp[s + v] = (ndp[s + v] + dp[s]) % MOD;

                if (s - v >= 0)
                    ndp[s - v] = (ndp[s - v] + dp[s]) % MOD;
            }

            dp.swap(ndp);
        }
    }

    cout << dp[X + offset] << '\n';

    return 0;
}