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
#include <cstdio>

int a[64], ret[64], z[4096], ret2[64];

int INF = 1 << 30;

int main()
{
  int n;
  scanf("%d", &n);
  
  
  
  for (int i = 0; i < n; i++)
  {
    scanf("%d", a + i);
    ret[i + 1] = INF;
  }
  
  int k = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = i + 1; j < n; j++)
    {
      if (a[i] > a[j])
      {
        z[k] = (1 << i) | (1 << j);
        k++;
      }
    }
  }
  
  for (int i = 0; i < (1 << n); i++)
  {
    int b = __builtin_popcount(i);
    
    int ile = 0;
    for (int j = 0; j < k; j++)
    {
      if ( (i & z[j]) == z[j])
      {
        ile++;
      }
    }
    if (ile < ret[b])
    {
      ret[b] = ile;
      ret2[b] = 1;
    }
    else if (ile == ret[b])
    {
      ret2[b]++;
    }
  }
  
  for (int i = 1; i <= n; i++)
  {
    printf("%d %d\n", ret[i], ret2[i]);
  }
  
  return 0;
}