fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class uniq_range_combinator
  5. {
  6. public:
  7. using range_value_t = int;
  8. using range_t = range<range_value_t>;
  9.  
  10. template <typename X>
  11. using list_t = std::list<X>;
  12.  
  13. uniq_range_combinator() = default;
  14.  
  15. template<typename FwdIt>
  16. list_t<std::vector<range_t>>&& operator()(FwdIt first, FwdIt last, size_t len)
  17. {
  18. len_ = len;
  19.  
  20. size_t ksz = std::distance(first, last);
  21. std::vector<range_t> res;
  22. res.reserve(ksz);
  23.  
  24. while(first != last)
  25. {
  26. const range_t& el = *first++;
  27. backtrack(first, last, el, 0, res);
  28. res.pop_back();
  29. }
  30.  
  31. return std::move(output_);
  32. }
  33.  
  34. private:
  35. template<typename FwdIt>
  36. void backtrack(FwdIt first, FwdIt last, const range_t& el,
  37. size_t len, std::vector<range_t>& res)
  38. {
  39. res.push_back(el);
  40. len += el.length();
  41.  
  42. if(len == len_)
  43. {
  44. output_.push_back(res);
  45. return;
  46. }
  47.  
  48. while(first != last /* && len < len_ */)
  49. {
  50. const range_t& next = *first++;
  51. size_t nl = len + next.length();
  52.  
  53. if(el.overlap(next) or nl > len_)
  54. continue;
  55.  
  56. backtrack(first, last, next, len, res);
  57. res.pop_back();
  58. }
  59. }
  60.  
  61. private:
  62. list_t<std::vector<range_t>> output_;
  63. size_t len_;
  64. };
  65.  
  66. int main() {
  67. // your code goes here
  68. return 0;
  69. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:8:25: error: ‘range’ does not name a type
         using range_t = range<range_value_t>;
                         ^~~~~
prog.cpp:11:29: error: ‘list’ in namespace ‘std’ does not name a template type
         using list_t = std::list<X>;
                             ^~~~
prog.cpp:16:9: error: ‘list_t’ does not name a type
         list_t<std::vector<range_t>>&& operator()(FwdIt first, FwdIt last, size_t len)
         ^~~~~~
prog.cpp:36:55: error: ‘range_t’ does not name a type
         void backtrack(FwdIt first, FwdIt last, const range_t& el,
                                                       ^~~~~~~
prog.cpp:37:41: error: ‘std::vector’ has not been declared
                        size_t len, std::vector<range_t>& res)
                                         ^~~~~~
prog.cpp:37:47: error: expected ‘,’ or ‘...’ before ‘<’ token
                        size_t len, std::vector<range_t>& res)
                                               ^
prog.cpp:62:9: error: ‘list_t’ does not name a type
         list_t<std::vector<range_t>> output_;
         ^~~~~~
prog.cpp: In member function ‘void uniq_range_combinator::backtrack(FwdIt, FwdIt, const int&, size_t, int)’:
prog.cpp:39:17: error: ‘res’ was not declared in this scope
                 res.push_back(el);
                 ^~~
prog.cpp:40:27: error: request for member ‘length’ in ‘el’, which is of non-class type ‘const int’
                 len += el.length();
                           ^~~~~~
prog.cpp:44:25: error: ‘output_’ was not declared in this scope
                         output_.push_back(res);
                         ^~~~~~~
prog.cpp:50:31: error: ‘range_t’ does not name a type
                         const range_t& next = *first++;
                               ^~~~~~~
prog.cpp:51:43: error: ‘std::next’ does not have class type
                         size_t nl = len + next.length();
                                           ^~~~
prog.cpp:53:31: error: request for member ‘overlap’ in ‘el’, which is of non-class type ‘const int’
                         if(el.overlap(next) or nl > len_)
                               ^~~~~~~
stdout
Standard output is empty