Cod sursa(job #3250419)

Utilizator iulia_morariuIuli Morariu iulia_morariu Data 20 octombrie 2024 19:28:25
Problema Diamant Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.58 kb
#include <iostream>
#include <fstream>
#include <vector>
//#include <bits/stdc++.h>
#define in fin
#define out fout
#define mod 10000

using namespace std;

ifstream fin("diamant.in");
ofstream fout("diamant.out");

int dp[801][88201];

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m, cost; in >> n >> m >> cost;
    vector<int> c;
    // avem la fiecare 2 cazuri : ignore (0), 1 sau -1

    // for(int i = 1; i <= n; i++){
    //     for(int j = 1; j <= m; j++){
    //         c.push_back( (i * j * 1) % mod );
    //         c.push_back( (i * j * (-1)) % mod );
    //     }
    // }

    int offs = (m * (m + 1)) / 2 * (n * (n + 1)) / 2;
    c.insert(c.begin(), 0);

    // cout << "v : ";
    // for(int i = 0; i < v.size(); i++) cout << v[i] << " ";
    // cout << '\n';

    int x = 1, y = 1;
    dp[0][offs] = 1; // 44100 e offsetu de la 0
    for(int i = 1; i <= 2 * n * m; i++){
        int c = x * y;
        if(i % 2 == 0) c = -c;
        // cout << " c = " << c << '\n';
        if(i % 2 == 0){
            y++;
            if(y == m + 1){
                y = 1; x++;
            }
        }
        for(int j = 0; j <= offs * 2; j++){
            dp[i][j] += dp[i - 1][j];
            dp[i][j] %= mod;
            if(j - c >= 0 && j - c <= offs * 2 && c > 0) dp[i][j] += dp[i - 1][j - c];
            else if(j - c >= 0 && j - c <= offs * 2 && c < 0) dp[i][j] += dp[i - 2][j - c];
            dp[i][j] %= mod;
        }
    }

    // cout << "offset = " << offs << '\n';
    // cout << dp[8][9] << '\n';

    out << dp[n * m * 2][offs + cost];

    return 0;
}