AhmedAshraff

Untitled

Jul 17th, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5. #define sz(s) (int)(s).size()
  6. #define all(s) s.begin(), s.end()
  7.  
  8. void Speed(){
  9. ios_base::sync_with_stdio(false);
  10. cin.tie(NULL);
  11. }
  12.  
  13. const int mod = 1e9 + 7;
  14.  
  15. ll power(ll a, ll n)
  16. {
  17. if(!n)
  18. return 1;
  19. ll res = power(a , n / 2);
  20. res = res * res % mod;
  21. if(n & 1)
  22. res = res * a % mod;
  23. return res;
  24. }
  25.  
  26. void solve(){
  27. vector<vector<ll>> arr(3 , vector<ll>(3));
  28. for(int i = 0; i < 3; i++)
  29. cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
  30.  
  31. vector<vector<pair<ll,ll>>> a(3);
  32. for(int j = 0; j < 3; j++){
  33. for(ll x = arr[j][0] - arr[j][2]; x <= arr[j][0] + arr[j][2]; x++){
  34. for(ll y = arr[j][1] - arr[j][2]; y <= arr[j][1] + arr[j][2]; y++){
  35. if((x - arr[j][0]) * (x - arr[j][0]) + (y - arr[j][1]) * (y - arr[j][1]) > arr[j][2] * arr[j][2])
  36. continue;
  37.  
  38. a[j].push_back({x,y});
  39. }
  40. }
  41. }
  42.  
  43. vector<int> inds = {0,1,2};
  44. ll num = 0 , denum = 0;
  45. do{
  46. int f = inds[0] , s = inds[1] , t = inds[2];
  47.  
  48. map<ll,pair<ll,ll>> mp_x , mp_y;
  49. for(auto& [x,y] : a[s]){
  50. mp_x[x].first++;
  51. mp_x[x].second += y;
  52. // mp_x[x].second %= mod;
  53. }
  54.  
  55. for(auto& [x,y] : a[t]){
  56. mp_y[y].first++;
  57. mp_y[y].second += x;
  58. // mp_y[y].second %= mod;
  59. }
  60.  
  61. for(auto&[x,y] : a[f]){
  62. auto p_x = mp_x[x];
  63. auto p_y = mp_y[y];
  64. ll d_y = abs(p_x.second - p_x.first * y) % mod;
  65. ll d_x = abs(p_y.second - p_y.first * x) % mod;
  66. num += d_x * d_y % mod;
  67. num %= mod;
  68. denum += p_x.first * p_y.first % mod;
  69. denum %= mod;
  70. }
  71. }while(next_permutation(all(inds)));
  72.  
  73. denum = denum * 2 % mod;
  74.  
  75. ll ans = num * power(denum , mod - 2) % mod;
  76. cout << ans << "\n";
  77.  
  78. }
  79.  
  80. int main(){
  81. freopen("triangle.in", "r", stdin);
  82. Speed();
  83. int tc = 1;
  84. // cin >> tc;
  85. while (tc--){
  86. solve();
  87. }
  88. return 0;
  89. }
Add Comment
Please, Sign In to add comment