fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4. map<vector<ll>,ll> a1;
  5. map<vector<ll>,ll> a2;
  6. map<vector<ll>,ll> a3;
  7. map<vector<ll>,ll> a4;
  8. map<vector<ll>,ll> a5;
  9. void combinationUtil(ll arr[], ll data[],
  10. ll start,ll end,
  11. ll index,ll r,ll g);
  12.  
  13.  
  14. void printCombination(ll arr[],ll n,ll r,ll g)
  15. {
  16. ll data[r];
  17. combinationUtil(arr, data, 0, n-1, 0, r,g);
  18. }
  19.  
  20.  
  21. void combinationUtil(ll arr[], ll data[],
  22. ll start, ll end,
  23. ll index, ll r,ll g)
  24. {
  25.  
  26. if(index==r)
  27. {
  28.  
  29. vector<ll> h;
  30. for(ll j = 0; j < r; j++)
  31. {
  32. ll m1=data[j];
  33. h.push_back(m1);
  34. }
  35. if(g==1)
  36. {
  37. a1[h]++;
  38. }
  39. if(g==2)
  40. {
  41. a2[h]++;
  42.  
  43. }
  44. if(g==3)
  45. {
  46. a3[h]++;
  47.  
  48.  
  49. }
  50. if(g==4)
  51. {
  52. a4[h]++;
  53.  
  54. }
  55. if(g==5)
  56. {
  57. a5[h]++;
  58. }
  59.  
  60. //cout << endl;
  61. return;
  62. }
  63.  
  64. // replace index with all possible
  65. // elements. The condition "end-i+1 >= r-index"
  66. // makes sure that including one element
  67. // at index will make a combination with
  68. // remaining elements at remaining positions
  69. for (ll i = start; i <= end &&
  70. end - i + 1 >= r - index; i++)
  71. {
  72. data[index] = arr[i];
  73. combinationUtil(arr, data, i+1,
  74. end, index+1, r,g);
  75. }
  76. }
  77. int main()
  78. {
  79. ios_base::sync_with_stdio(false);
  80. cin.tie(NULL);
  81. cout.tie(NULL);
  82.  
  83. ll t;
  84. cin>>t;
  85. ll i1=1;
  86. while(t--)
  87. {
  88. ll n,s;
  89. cin>>n>>s;
  90. ll a[n+5][8];
  91. ll b[79]={0};
  92. a1.clear();
  93. a2.clear();
  94. a3.clear();
  95. a4.clear();
  96. a5.clear();
  97.  
  98. ll i=1;
  99. while(i<=n)
  100. {
  101. ll x;
  102. cin>>x;
  103. b[x]++;
  104. ll arr[x];
  105. ll j=0;
  106. while(j<x)
  107. {
  108.  
  109. cin>>arr[j];
  110.  
  111. j++;
  112. }
  113. sort(arr,arr+x);
  114. a[i][0]=x;
  115. j=1;
  116. while(j<=x)
  117. {
  118. a[i][j]=arr[j-1];
  119. j++;
  120. }
  121. ll pass=1;
  122. while(pass<=x)
  123. {
  124. printCombination(arr,x,pass,x);
  125. pass++;
  126. }
  127. i++;
  128. }
  129. ll c1=0;
  130. i=1;
  131. while(i<=n)
  132. {
  133.  
  134. ll x=a[i][0];
  135. vector<ll> h;
  136. ll j=1;
  137. while(j<=x)
  138. {
  139.  
  140. h.push_back(a[i][j]);
  141.  
  142. j++;
  143. }
  144.  
  145.  
  146. ll pass=1;
  147. while(pass<=x-1)
  148. {
  149. c1=c1+b[pass];
  150. pass++;
  151. }
  152.  
  153.  
  154. pass=x;
  155. while(pass<=5)
  156. {
  157.  
  158.  
  159.  
  160. // c1=c1+ (b[pass]-a[h]);
  161. if(pass==1)
  162. {
  163. c1=c1+ (b[pass]-a1[h]);
  164. }
  165. if(pass==2)
  166. {
  167. c1=c1+ (b[pass]-a2[h]);
  168.  
  169. }
  170. if(pass==3)
  171. {
  172. c1=c1+ (b[pass]-a3[h]);
  173.  
  174.  
  175. }
  176. if(pass==4)
  177. {
  178. c1=c1+ (b[pass]-a4[h]);
  179.  
  180. }
  181. if(pass==5)
  182. {
  183. c1=c1+ (b[pass]-a5[h]);
  184. }
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194. pass++;
  195. }
  196.  
  197.  
  198.  
  199.  
  200. i++;
  201. }
  202.  
  203.  
  204. cout<<"Case #";
  205. cout<<i1;
  206. cout<<": ";
  207.  
  208. cout<<c1;
  209. i1++;
  210.  
  211.  
  212.  
  213. cout<<"\n";
  214. }
  215.  
  216. return 0;
  217. }
Success #stdin #stdout 0s 4264KB
stdin
2
4 100
4 80 90 100 5
1 90
1 80
3 80 90 100
3 30
4 10 11 12 13
4 10 11 12 13
5 25 26 27 28 29
stdout
Case #1: 7
Case #2: 4