fork(1) download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <limits>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. bool generate(vector<int>& temp, int& target, const size_t width, const size_t i) {
  9. const auto replacement = temp[i];
  10. const auto result = target > replacement;
  11.  
  12. if (result) {
  13. for_each(begin(temp), next(begin(temp), min(temp.size(), i + width - 1)), [=](auto& it) {
  14. if (target == it) {
  15. it = replacement;
  16. } else if (target < it) {
  17. --it;
  18. } });
  19. }
  20. target = replacement;
  21. return result;
  22. }
  23.  
  24. int main() {
  25. const vector<char> rooms = { 0b1101, 0b110, 0b1101, 0b110, 0b1100, 0b101, 0b110,
  26. 0b1110, 0b1001, 0b110, 0b1011, 0b1010, 0b1111, 0b1010,
  27. 0b1000, 0b101, 0b11, 0b1110, 0b1011, 0b1110, 0b1010,
  28. 0b1011, 0b1101, 0b101, 0b1, 0b101, 0b11, 0b1011 };
  29. const size_t width = 7U;
  30. auto result = 0;
  31. vector<int> temp(rooms.size());
  32.  
  33. for (size_t i = 0U; i < rooms.size(); ++i) {
  34. const auto toWest = (rooms[i] & 0b1000) == 0;
  35. const auto toNorth = (rooms[i] & 0b100) == 0;
  36. const auto toEast = (rooms[i] & 0b10) == 0;
  37. const auto toSouth = (rooms[i] & 0b1) == 0;
  38. const auto west = toWest && temp[i - 1] != 0 ? temp[i - 1] : numeric_limits<int>::max();
  39. const auto north = toNorth && temp[i - width] != 0 ? temp[i - width] : numeric_limits<int>::max();
  40. const auto east = toEast && temp[i + 1] != 0 ? temp[i + 1] : numeric_limits<int>::max();
  41.  
  42. temp[i] = min({ temp[i] != 0 ? temp[i] : numeric_limits<int>::max(), result + 1, west, north, east });
  43.  
  44. if (temp[i] == result + 1) ++result;
  45.  
  46. if (toWest) result -= generate(temp, temp[i - 1], width, i);
  47. if (toNorth) result -= generate(temp, temp[i - width], width, i);
  48. if (toEast) result -= generate(temp, temp[i + 1], width, i);
  49. if (toSouth) temp[i + width] = temp[i];
  50. }
  51.  
  52. for (auto it = cbegin(temp); it != cend(temp);) {
  53. for (auto i = 0; i < width; ++i, ++it) cout << *it << '\t';
  54. cout << endl;
  55. }
  56.  
  57. cout << endl << result << endl;
  58. }
Compilation error #stdin compilation error #stdout 0s 3456KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'generate(std::vector<int>&, int&, size_t, size_t)::<lambda(auto:1&)> [with auto:1 = int]':
/usr/include/c++/5/bits/stl_algo.h:3767:5:   required from '_Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Funct = generate(std::vector<int>&, int&, size_t, size_t)::<lambda(auto:1&)>]'
prog.cpp:18:7:   required from here
prog.cpp:15:8: internal compiler error: Segmentation fault
     it = replacement;
        ^
0x8699cca crash_signal
	../../src/gcc/toplev.c:383
0x82f9748 maybe_constant_init(tree_node*, tree_node*)
	../../src/gcc/cp/constexpr.c:3843
0x8226605 tsubst_copy
	../../src/gcc/cp/pt.c:13114
0x8217f03 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../src/gcc/cp/pt.c:15705
0x821917c tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../src/gcc/cp/pt.c:15033
0x821fde7 tsubst_expr
	../../src/gcc/cp/pt.c:14530
0x821eee1 tsubst_expr
	../../src/gcc/cp/pt.c:13941
0x821fdac tsubst_expr
	../../src/gcc/cp/pt.c:14113
0x821f153 tsubst_expr
	../../src/gcc/cp/pt.c:14093
0x821fdac tsubst_expr
	../../src/gcc/cp/pt.c:14113
0x821f672 tsubst_expr
	../../src/gcc/cp/pt.c:13927
0x821fdac tsubst_expr
	../../src/gcc/cp/pt.c:14113
0x821eaac instantiate_decl(tree_node*, int, bool)
	../../src/gcc/cp/pt.c:20543
0x824c1a3 mark_used(tree_node*, int)
	../../src/gcc/cp/decl2.c:5032
0x81eef12 build_over_call
	../../src/gcc/cp/call.c:7501
0x81f1309 build_op_call_1
	../../src/gcc/cp/call.c:4345
0x81f1309 build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
	../../src/gcc/cp/call.c:4368
0x82b23fa finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, bool, int)
	../../src/gcc/cp/semantics.c:2426
0x8219406 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../src/gcc/cp/pt.c:15343
0x821fde7 tsubst_expr
	../../src/gcc/cp/pt.c:14530
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-5/README.Bugs> for instructions.
stdout
Standard output is empty