Cod sursa(job #1760714)

Utilizator DobosDobos Paul Dobos Data 21 septembrie 2016 09:46:50
Problema Abc2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.68 kb
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

const int NMax = 1e5 + 5;

int Count[42][42];
bool Bad[42][42];
ll Square[42][42];
ll Ans[42][42];

int main(){

    #ifndef ONLINE_JUDGE
    freopen("a.in", "r", stdin);
    #endif // ONLINE_JUDGE

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m, k;
    cin >> n >> m >> k;

    char c;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){

            cin >> c;
            Bad[i][j] = (c - '0');

            Count[i][j] += Bad[i][j];
            Count[i][j] += Count[i - 1][j] + Count[i][j - 1] - Count[i - 1][j - 1];

        }
    }

    /*for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cout << Count[i][j] << " ";
        }
        cout << "\n";
    }*/

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            for(int a = 1; a <= i; a++){
                for(int b = 1; b <= j; b++){

                    int block = Count[i][j] - Count[i][b - 1] - Count[a - 1][j] + Count[a - 1][b - 1];
                    if(block == 0){
                        Square[i][j]++;
                    }
                }
            }

            if(Bad[i][j] == false){
                Ans[i][j] = Square[i][j] + Ans[i - 1][j] + Ans[i][j - 1] - Ans[i - 1][j - 1];
            }
            if(Bad[i][j - 1] == true || Bad[i - 1][j] == true){
                Ans[i][j] += Ans[i - 1][j - 1];
            }
        }
    }

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cout << Ans[i][j] << " ";
        }
        cout << "\n";
    }

    return 0;
}