Cod sursa(job #2014787)

Utilizator stefan_creastaStefan Creasta stefan_creasta Data 24 august 2017 13:52:06
Problema Diamant Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <cstdio>
#include <algorithm>
using namespace std;
const int LIM = 45000;
int v[LIM * 2], b[LIM * 2], a[405];

int main ()
{
    int n, m, k, i, j, nr = 0;
    freopen("diamant.in","r",stdin);
    freopen("diamant.out","w",stdout);
    scanf("%d%d%d",&n,&m,&k);
    for(i = 1;i <= n; ++i)
        for(j = 1;j <= m; ++j)
            a[++nr] = i * j;
    int st = LIM, dr = LIM;
    for(j = 1;j <= nr; ++j) {
        for(i = st;i <= dr; ++i) {
            if(v[i] > 0) {
                b[i + a[j]] += v[i];
                b[i - a[j]] += v[i];
                dr = max(dr, i + a[j]);
                st = min(st, i - a[j]);
            }
        }
        ++b[LIM + a[j]];
        ++b[LIM - a[j]];
        dr = max(dr, LIM + a[j]);
        st = min(st, LIM - a[j]);
        for(i = st;i <= dr; ++i)
            v[i] = b[i] % 10000;
    }
    ++v[LIM];
    if(k > LIM || k < -45000)
        printf("0");
    else
        printf("%d", v[LIM + k] % 10000);
    return 0;
}