fork download
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. struct Partition
  7. {
  8. size_t _size;
  9. size_t _length;
  10. vector<size_t> _parts;
  11.  
  12. void conjugate()
  13. {
  14. size_t space = 0;
  15. for (size_t i = 0; i < _length; ++i)
  16. space = max(space, _parts[i] + i);
  17. ++space;
  18.  
  19. _parts.resize(space);
  20. reverse(begin(_parts), end(_parts));
  21.  
  22. auto it_out = begin(_parts);
  23. auto it_in = end(_parts) - _length;
  24. size_t prev = 0;
  25.  
  26. for (; it_in < end(_parts); ++it_in)
  27. {
  28. it_out = fill_n(it_out, *it_in - prev, end(_parts) - it_in);
  29. prev = *it_in;
  30. }
  31.  
  32. _length = it_out - begin(_parts);
  33. _parts.resize(_length);
  34. }
  35.  
  36. void print()
  37. {
  38. for (auto x: _parts)
  39. cout << x << ' ';
  40.  
  41. cout << '\n';
  42. }
  43. };
  44.  
  45. int main()
  46. {
  47. Partition a {14, 4, {5, 4, 4, 1}};
  48. a.print();
  49. a.conjugate();
  50. a.print();
  51. }
  52.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
5 4 4 1 
4 3 3 3 1