fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<bool> safe;
  6. int S;
  7. set<pair<int, int>> vis;
  8. void dfs(int cur, int speed) {
  9. if (vis.count(pair<int, int>(cur, speed)) != 0)
  10. return;
  11. if (cur > safe.size())
  12. return;
  13. vis.insert(pair<int, int>(cur, speed));
  14. vector<int> newSpeeds = {max(speed - 1, 1), speed, speed + 1};
  15. for (auto s : newSpeeds) {
  16. if (cur + s < safe.size() && safe[cur + s])
  17. dfs(cur + s, s);
  18. }
  19. return;
  20. }
  21.  
  22. int main() {
  23. safe = {true, false, true, true, true, false, true, true, false, true, true};
  24. S = 4;
  25. dfs(0, S);
  26. vector<bool> reachable(safe.size());
  27. for (auto i : vis) {
  28. reachable[i.first] = true;
  29. }
  30. for (auto i : reachable) {
  31. cout << i << ' ';
  32. }
  33. cout << endl;
  34. }
Success #stdin #stdout 0s 4356KB
stdin
Standard input is empty
stdout
1 0 0 1 1 0 1 1 0 1 1