Cod sursa(job #2961491)

Utilizator Dragono63Stanciu Rares Stefan Dragono63 Data 6 ianuarie 2023 16:11:27
Problema Diamant Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.88 kb
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
using ll = long long;
using ci = const int;
using cll = const long long;

using namespace std;

const int SMAX = 44200;
const int MOD = 10000;
/*******************************/
// INPUT / OUTPUT

ifstream f("diamant.in");
ofstream g("diamant.out");
/*******************************/
/// GLOBAL DECLARATIONS

int N, M, X;
int SUM_MAX, ans;
short dp[2][2 * SMAX];
/*******************************/
/// FUNCTIONS

void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
    f >> N >> M >> X;
}
///-------------------------------------
inline void Solution()
{
    for (int i = 1 ; i <= N ; ++ i)
        for (int j = 1 ; j <= M ; ++ j)
            SUM_MAX += i * j;
    
    if (SUM_MAX < abs(X)) return;

    dp[0][SMAX] = 1;
    int w, t = 1, st, dr, sum_ramas = SUM_MAX;
    for (int i = 1 ; i <= N ; ++ i)
    {
        for (int j = 1 ; j <= M ; ++ j)
        {
            w = i * j;
            sum_ramas -= w;
            st = max(X - sum_ramas, -SMAX + w);
            dr = min(X + sum_ramas, SMAX - w);

            for (int s = st ; s <= dr ; ++ s)
            {
                dp[t][SMAX + s] = dp[t ^ 1][SMAX + s];
                dp[t][SMAX + s] += dp[t ^ 1][SMAX + s - w];
                if (dp[t][SMAX + s] >= MOD) dp[t][SMAX + s] -= MOD; 
                dp[t][SMAX + s] += dp[t ^ 1][SMAX + s + w]; 
                if (dp[t][SMAX + s] >= MOD) dp[t][SMAX + s] -= MOD; 
            }
            t ^= 1;
        }
    }
    
    t = ((N * M) & 1);
    ans = dp[t][SMAX + X];
}
///-------------------------------------
inline void Output()
{
    g << ans;
}
///-------------------------------------
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ReadInput();
    Solution();
    Output();
    return 0;
}