// Karol Kosinski 2019 #include <cstdio> #include <algorithm> #define FOR(i,a,b) for(int i=(a);i<(b);++i) //#define DEBUG(x...) printf(x) #define DEBUG(x...) using namespace std; const int NX = 42; int P[NX], Ones[NX], Aux[NX]; unsigned int R[NX][NX * NX]; int process(int n) { int ix = 0, res = 0; FOR(i,0,n) if (Ones[i]) { Aux[ix++] = P[i]; DEBUG("%d ", i + 1); } DEBUG("\n"); FOR(i,0,ix) FOR(j,i+1,ix) if (Aux[i] > Aux[j]) ++res; return res; } int main() { int n; scanf("%d", &n); FOR(i,0,n) scanf("%d", P + i); FOR(i,0,n) { Ones[i] = 1; do { ++R[i][process(n)]; } while (prev_permutation(Ones, Ones + n)); int min_k = 0; while (not R[i][min_k]) ++min_k; printf("%d %u\n", min_k, R[i][min_k]); } return 0; }
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 | // Karol Kosinski 2019 #include <cstdio> #include <algorithm> #define FOR(i,a,b) for(int i=(a);i<(b);++i) //#define DEBUG(x...) printf(x) #define DEBUG(x...) using namespace std; const int NX = 42; int P[NX], Ones[NX], Aux[NX]; unsigned int R[NX][NX * NX]; int process(int n) { int ix = 0, res = 0; FOR(i,0,n) if (Ones[i]) { Aux[ix++] = P[i]; DEBUG("%d ", i + 1); } DEBUG("\n"); FOR(i,0,ix) FOR(j,i+1,ix) if (Aux[i] > Aux[j]) ++res; return res; } int main() { int n; scanf("%d", &n); FOR(i,0,n) scanf("%d", P + i); FOR(i,0,n) { Ones[i] = 1; do { ++R[i][process(n)]; } while (prev_permutation(Ones, Ones + n)); int min_k = 0; while (not R[i][min_k]) ++min_k; printf("%d %u\n", min_k, R[i][min_k]); } return 0; } |