fork(2) download
  1. #include <stdio.h>
  2. #include <vector>
  3. int main(){
  4. const int g = 6;
  5. int c = 0;
  6. bool a[g*g-1] = {true};
  7. std::vector<int> s{1};
  8. while(!s.empty()){
  9. auto p = s.back();
  10. s.pop_back();
  11. if(p < 0) a[-p] = false;
  12. else if(p == g*g-1) c++;
  13. else if(!a[p]){
  14. a[p] = true;
  15. s.push_back(-p);
  16. if(p%g < g-1) s.push_back(p+1);
  17. if(p/g < g-1) s.push_back(p+g);
  18. if(p%g > 0) s.push_back(p-1);
  19. if(p/g > 0) s.push_back(p-g);
  20. }}
  21. printf("%d\n", c*2);
  22. return 0;
  23. }
Success #stdin #stdout 0.42s 3456KB
stdin
Standard input is empty
stdout
1262816