fork download
  1. #include<bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. #define ll long long
  7. #define pi 3.14159265358979323846
  8. #define pb push_back
  9. #define ar array
  10.  
  11. template<typename T, typename cmp = std::greater<T>>
  12. using pq = priority_queue<T, vector<T>, cmp>;
  13.  
  14. template<typename T, typename cmp = std::less<T>>
  15. using ordered_set = tree<T, __gnu_pbds::null_type, cmp, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
  16.  
  17. void chay()
  18. {
  19. ios_base::sync_with_stdio(0);
  20. cin.tie(0);
  21. cout.tie(0);
  22. #define task "Hi"
  23. freopen(task".INP", "r", stdin);
  24. freopen(task".OUT", "w", stdout);
  25. }
  26.  
  27. const int N = 1e6, INF = 2e9+7;
  28. const int block = 600;
  29. const long long INFLL = 2e18+7;
  30. long long M = 1e9+7;
  31.  
  32. struct Point {
  33. ll x, y;
  34. Point(int _x, int _y)
  35. {
  36. x = _x;
  37. y = _y;
  38. }
  39. };
  40.  
  41. ll gcdll(ll a, ll b) {
  42. return b == 0 ? abs(a) : gcdll(b, a % b);
  43. }
  44.  
  45. void solve()
  46. {
  47. int n;
  48. cin>>n;
  49. vector<Point> p;
  50. p.pb(Point(0, 0));
  51. for (int i = 1; i <= n; i++)
  52. {
  53. int huong, d;
  54. cin>>huong>>d;
  55. Point toado = *p.rbegin();
  56. if (huong == 1)
  57. {
  58. toado.y += d;
  59. }
  60. if (huong == 2)
  61. {
  62. toado.x += d;
  63. }
  64. if (huong == 3)
  65. {
  66. toado.y -= d;
  67. toado.x += d;
  68. }
  69. if (huong == 4)
  70. {
  71. toado.y -= d;
  72. }
  73. if (huong == 5)
  74. {
  75. toado.x -= d;
  76. }
  77. if (huong == 6)
  78. {
  79. toado.y += d;
  80. toado.x -= d;
  81. }
  82. p.push_back(toado);
  83. }
  84.  
  85. ll area2 = 0; // diện tích * 2
  86. ll B = 0; // số điểm biên
  87. for (int i = 0; i < n; i++) {
  88. int j = (i + 1) % n;
  89. area2 += (p[i].x * p[j].y - p[j].x * p[i].y);
  90. B += gcdll(abs(p[j].x - p[i].x), abs(p[j].y - p[i].y));
  91. }
  92.  
  93. ll A = abs(area2); // diện tích * 2
  94. ll I2 = A - B + 2; // = 2I
  95. ll I = I2 / 2;
  96. cout<<(I + B)%M;
  97. }
  98.  
  99. signed main ()
  100. {
  101. //chay();
  102. ios_base::sync_with_stdio(0);
  103. cin.tie(0);
  104. cout.tie(0);
  105. int t = 1;
  106. //cin>>t;
  107. while (t--)
  108. {
  109. solve();
  110. }
  111.  
  112. return 0;
  113. }
  114.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
1