fork download
  1. /* author: Priyanshu Shrivastav, from IIT Palakkad *
  2.  * *_ __ ___ _ ______ ___ _ ____ ___ ___| |_ *
  3.  * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
  4.  * | | | | | | | | (_| (_) | | | \ V /| | (__| |_ *
  5.  * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
  6. When I wrote this, only God and I understood what I was doing
  7.  ** * * * * * * * Now, only God knows * * * * * * */
  8.  
  9. #include <bits/stdc++.h>
  10. #include <ext/pb_ds/assoc_container.hpp>
  11. #include <ext/pb_ds/tree_policy.hpp>
  12. using namespace __gnu_pbds;
  13. using namespace std;
  14.  
  15. #define pb push_back
  16. #define eb emplace_back
  17. #define mp make_pair
  18. #define se second
  19. #define fi first
  20. #define all(v) (v).begin(),(v).end()
  21. #define rall(v) (v).rbegin(), (v).rend()
  22. #define Sqr(x) ((x)*(x))
  23. #define Mod(x) ((x)%_mod)
  24. #define inf (0x7fffffff)
  25. #define eps ((double)1e-9)
  26. #define maxn ((int)1e5+10)
  27.  
  28. typedef long long ll;
  29.  
  30. const int _mod = (int)1e9 + 7;
  31.  
  32. vector < vector <int> > p;
  33.  
  34. void solve (vector <int> v1, int x, int n) {
  35. if (x == n) return;
  36. if (x == n) return;
  37. for (int i = 0; i < n; ++i) {
  38. swap (v1[x], v1[i]);
  39. if (x == n - 1) p.pb (v1);
  40.  
  41. solve (v1, x + 1, n);
  42. swap (v1[x], v1[i]);
  43. }
  44. }
  45. vector <pair <int, vector <int> >> ps;
  46.  
  47. int main() {
  48. #ifdef CONVICTION
  49. freopen ("in", "r", stdin);
  50. #endif
  51. ios_base::sync_with_stdio(false);
  52. cin.tie (NULL); cout.precision (10); cout << fixed;
  53.  
  54. /*solution starts here...*/
  55. int n = 6;
  56.  
  57. vector <int> v;
  58. for (int i = 1; i <= n; ++i) v.pb (i);
  59. solve (v, 0, n);
  60. sort (all (p));
  61.  
  62. int count = 1;
  63. for (int i = 0, j = i + 1; i < (int) p.size() - 1; ) {
  64. count = 1;
  65. while (j < (int) p.size() && p[i] == p[j]) {
  66. ++count;
  67. ++j;
  68. }
  69. ps.pb ({count, p[i]});
  70. i = j, j = i + 1;
  71. }
  72.  
  73. sort (all (ps));
  74. // cout << "max "; cout << ps[ps.size() - 1].fi << ' ' ;
  75. for (auto it : ps[ps.size() - 1].se) cout << it << ' '; cout << '\n';
  76. //cout << "min "; cout << ps[0].fi << ' ';
  77. for (auto it : ps[0].se) cout << it << ' '; cout << '\n';
  78. return 0;
  79. }
  80.  
  81.  
Success #stdin #stdout 0.01s 16760KB
stdin
Standard input is empty
stdout
2 3 1 5 6 4 
6 1 2 3 4 5