fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. struct Knap
  6. {
  7. unsigned int a;
  8. unsigned int b;
  9. };
  10.  
  11. int main()
  12. {
  13. unsigned size, pyramids, vertex, sum = 0;
  14. Knap temp;
  15. std::cin >> size;
  16. ++size;
  17. std::cin >> pyramids;
  18. std::vector<std::vector<bool> > board;
  19. board.resize(size, std::vector<bool>(size, false));
  20. for (int i = 0; i < pyramids; ++i)
  21. {
  22. std::cin >> temp.a;
  23. std::cin >> temp.b;
  24. std::cin >> vertex;
  25. board[temp.a][temp.b] = true;
  26. unsigned int a;
  27. if (temp.b <= size)
  28. for (int a = temp.a + 1; a <= vertex + temp.a && a < size; ++a)
  29. board[a][temp.b] = true;
  30. a = temp.a;
  31. for (unsigned int b = temp.b + 1; a <= vertex + temp.a && a < size && b <= temp.b + vertex && b < size; ++a, ++b)
  32. board[a][b] = true;
  33. for (Knap z = {temp.a + 2, temp.b + 1}; z.a <= temp.a + vertex * 2 && z.a < size && z.b <= temp.b + vertex && z.b < size; z.a += 2, ++z.b)
  34. board[z.a][z.b] = true;
  35.  
  36. }
  37. for (auto x : board)
  38. sum += std::count(x.begin(), x.end(), true);
  39. std::cout << sum;
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 4416KB
stdin
5 2
2 1 1
2 2 2
stdout
8