1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <vector>

using namespace std;

int power(int base, int exp) {
    if (exp == 0) return 1;
    if (exp == 1) return base;
    return base*power(base, exp-1);
}

int countOnes(string bitset) {
    int count = 0;
    for(char a: bitset) {
        if (a == '1') count++;
    }
    return count;
}

int main() {
    int licz;
    cin >> licz;

    int atak[licz] = {0};
    int counter[licz] = {0};
    vector<int> currTest;

    for (int i = 0; i < licz; i++) {
        cin >> atak[i];
    }

    int currMin[licz];
    for (int i = 0; i < licz; i ++) {
        currMin[i] = 40000000;
    }
    for (int i = 1; i < power(2, licz); i++) {
        int copy = i;
        string res = "";
        while (copy != 0) {
            res += to_string(copy%2);
            copy /= 2;
        }
        while (res.length() < licz) res += "0";

        for (int j = 0; j < licz; j++) {
            if (res[j] == '1') {
                currTest.push_back(atak[j]);
            }
        }

        int smaller = 0;

        for (int j = 0; j < currTest.size(); j++) {
            for (int k = j+1; k < currTest.size(); k++) {
                if (currTest[j] > currTest[k]) smaller += 1;
            }
        }

        if (smaller < currMin[countOnes(res)-1]) {
            currMin[countOnes(res)-1] = smaller;
            counter[countOnes(res)-1] = 1;
        }
        else if (smaller == currMin[countOnes(res)-1]) counter[countOnes(res)-1]++;

        for (int u = 0; u < licz; u++) {
            //cout << counter[u] << " ";
        }
        //cout << " | ";
        for (int u = 0; u < licz; u++) {
            //cout << currMin[u] << " ";
        }

        //cout << countOnes(res) << ":" <<  res << "-->" << smaller << endl;
        currTest.clear();
    }

    for (int i = 0; i < licz; i++) {
        cout << currMin[i] << " " << counter[i] << endl;
    }

    return 0;
}