Cod sursa(job #2913878)

Utilizator vlad2009Vlad Tutunaru vlad2009 Data 17 iulie 2022 16:13:18
Problema Prod Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <fstream>

using namespace std;

const int MAX_N = 1e3;
int fr[MAX_N + 1];
int a[MAX_N + 1], b[MAX_N + 1], c[100 * MAX_N];

bool comp() {
    if (a[0] < b[0]) {
        return 1;
    } else if (a[0] > b[0]) {
        return 0;
    }
    for (int i = a[0]; i >= 1; i--) {
        if (a[i] < b[i]) {
            return 1;
        } else if (a[i] < b[i]) {
            return 0;
        }
    }
    return 0;
}

int main() {
    ifstream fin("prod.in");
    ofstream fout("prod.out");
    for (int i = 1; i <= 9; i++) {
        fin >> fr[i];
    }
    for (int i = 9; i >= 1; i--) {
        for (int j = 1; j <= fr[i]; j++) {
            if (comp()) {
                a[++a[0]] = i;
            } else {
                b[++b[0]] = i;
            }
        }
    }
    for (int i = a[0]; i >= 1; i--)  {
        for (int j = b[0]; j >= 1; j--) {
            c[a[0] - i + b[0] - j + 1] += a[i] * b[j];
        }
    }
    c[0] = a[0] + b[0] - 1;
    int t = 0, i = 1;
    for (; i <= c[0] || t > 0; i++) {
        t += c[i];
        c[i] = t % 10;
        t /= 10;
    }
    i--;
    c[0] = max(c[0], i);
    for (int i = c[0]; i >= 1; i--) {
        fout << c[i];
    }
    return 0;
}