Cod sursa(job #2203884)

Utilizator vladisimovlad coneschi vladisimo Data 13 mai 2018 16:05:15
Problema Diamant Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Semestrul 2 Marime 0.86 kb
#include <stdio.h>
#include <algorithm>
#define nr1(x) (x % n) * (x  / n + 1)
#define nr2(x) n * (i / n)

const int MAX_X = 44100;
const int MOD = 10000;

int Count[2][1000 + MAX_X];

int main() {
  freopen("diamant.in", "r", stdin);
  freopen("diamant.out", "w", stdout);
  int n, m, x;
  scanf("%d%d%d", &n, &m, &x);
  x = std::abs(x);
  if (x >= MAX_X)
    printf("0");
  else {
    Count[0][0] = 1;
    for (int i = 1; i <= n * m; i++) {
      int plus = nr1(i);
      if (i % n == 0)
        plus = nr2(i);
      for (int j = 0; j + plus <= MAX_X; j++) {
        int p = std::abs(j - plus);
        if (p >= MAX_X || j + plus >= MAX_X)
          break;
        Count[i % 2][j] = (Count[(i - 1) % 2][j] + Count[(i - 1) % 2][j + plus] + Count[(i - 1) % 2][p]) % MOD;
      }
    }
    printf("%d", Count[(n * m) % 2][x]);
  }
  return 0;
}