Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6.  
  7. bool valid(int r, int c, int n)
  8. {
  9. return (1 <= r && 1 <= c && r <= n && c <= n);
  10. }
  11.  
  12. ll solve(int n)
  13. {
  14. set <pair <int, int>> s;
  15. for (int i = 1; i <= n; i++)
  16. {
  17. s.insert({1, i});
  18. s.insert({2, i});
  19. s.insert({3, i});
  20. s.insert({n, i});
  21. s.insert({n - 1, i});
  22. s.insert({n - 2, i});
  23. s.insert({n - 3, i});
  24. }
  25. set <pair <int, int>> s2;
  26. for (auto &it : s)
  27. {
  28. s2.insert({it.first, it.second});
  29. s2.insert({it.second, it.first});
  30. }
  31. s = s2;
  32.  
  33. ll res = 0LL;
  34.  
  35. for (auto &it : s)
  36. {
  37. int r = it.first, c = it.second;
  38. if (valid(r, c, n) == 0) continue;
  39. int good = n * n - 1;
  40. for (int dx = -2; dx <= 2; dx++)
  41. {
  42. for (int dy = -2; dy <= 2; dy++)
  43. {
  44. if (abs(dx) + abs(dy) != 3) continue;
  45. int rn = r + dx;
  46. int cn = c + dy;
  47. good -= valid(rn, cn, n);
  48. }
  49. }
  50. res += good;
  51. }
  52. ll total = n * (ll) n, lft = total - (ll) s.size();
  53. if (lft >= 0)
  54. {
  55. res += lft * (total - 9);
  56. }
  57. return res / 2;
  58. }
  59.  
  60. int main()
  61. {
  62. ios_base::sync_with_stdio(false);
  63. cin.tie(0); cout.tie(0);
  64.  
  65. int n;
  66. cin >> n;
  67. for (int i = 1; i <= n; i++)
  68. {
  69. cout << solve(i) << "\n";
  70. }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement