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. int dx[] = {0, -1, 1};
  11. int dy[] = {1, 1, 1};
  12.  
  13. void simulate(int x, int y, int level, int direction) {
  14. if (level == t.size()) return;
  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. ios::sync_with_stdio(false);
  28. cin.tie(nullptr);
  29.  
  30. int n;
  31. cin >> n;
  32. t.resize(n);
  33.  
  34. for (int i = 0; i < n; ++i) {
  35. cin >> t[i];
  36. }
  37.  
  38. visitedCells.insert({0, 0});
  39. simulate(0, 0, 0, 0);
  40.  
  41. cout << visitedCells.size() << "\n";
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5288KB
stdin
4
4 2 2 3
stdout
32