fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4.  
  5. using namespace std;
  6.  
  7. set<pair<int, int>> visitedCells;
  8. vector<int> t;
  9.  
  10. void simulate(int x, int y, int level, int direction) {
  11. if (level == t.size()) return;
  12.  
  13. int dx[] = {0, -1, 1, -1, 1};
  14. int dy[] = {1, 1, 1, 0, 0};
  15.  
  16. for (int i = 0; i < t[level]; ++i) {
  17. x += dx[direction];
  18. y += dy[direction];
  19. visitedCells.insert({x, y});
  20. }
  21.  
  22. simulate(x, y, level + 1, 1);
  23. simulate(x, y, level + 1, 2);
  24. }
  25.  
  26. int main() {
  27. int n;
  28. cin >> n;
  29. t.resize(n);
  30.  
  31. for (int i = 0; i < n; ++i) {
  32. cin >> t[i];
  33. }
  34.  
  35. visitedCells.insert({0, 0});
  36. simulate(0, 0, 0, 0);
  37.  
  38. cout << visitedCells.size() << "\n";
  39. return 0;
  40. }
Success #stdin #stdout 0s 5288KB
stdin
4
4 2 2 3
stdout
32