Cod sursa(job #2071956)

Utilizator giotoPopescu Ioan gioto Data 21 noiembrie 2017 10:58:54
Problema Diamant Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <bits/stdc++.h>
using namespace std;

int n, m, x;
const int VMAX = 44100 * 2;
const int MOD = 10000;
int d[VMAX + 5], c[VMAX + 5], mod[20005];
int main(){
    freopen("diamant.in", "r", stdin);
    freopen("diamant.out", "w", stdout);
    scanf("%d%d%d", &n, &m, &x);
    d[44100] = 1;
    c[44100] = 1;
    for(int i = 1; i < 20000 ; ++i)
        mod[i] = (i > MOD) ? (i - MOD) : i;
    for(int i = 1; i <= n ; ++i){
        for(int j = 1; j <= m ; ++j){
            int cr = i * j;
            for(int t = VMAX; t >= cr ; --t)
                d[t] = mod[d[t] + d[t - i * j]];
            cr = VMAX - i * j;
            for(int t = 0; t <= cr ; ++t){
                d[t] = mod[c[t + i * j] + d[t]];
                c[t] = d[t];
            }
            for(int t = cr + 1; t <= VMAX ; ++t)
                c[t] = d[t];
        }
    }
    if(x <= 44100 && x >= -44100) printf("%d", d[x + 44100]);
    else printf("0");
    return 0;
}