sacgajcvs

Untitled

Oct 15th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. /*
  2. _____ _ _ _ _
  3. |_ _| |__ ___ / \ _ __ ___| |__ _ _| |
  4. | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  5. | | | | | | __// ___ \| | | \__ \ | | | |_| | |
  6. |_| |_| |_|\___/_/ \_\_| |_|___/_| |_|\__,_|_|
  7.  
  8. */
  9. #include<bits/stdc++.h>
  10. #include <ext/pb_ds/assoc_container.hpp>
  11. #include <ext/pb_ds/tree_policy.hpp>
  12. #define ll long long
  13. #define pb push_back
  14. #define ppb pop_back
  15. #define endl '\n'
  16. #define mii map<ll,ll>
  17. #define msi map<string,ll>
  18. #define mis map<ll, string>
  19. #define rep(i,a,b) for(ll i=a;i<b;i++)
  20. #define repr(i,a,b) for(ll i=b-1;i>=a;i--)
  21. #define trav(a, x) for(auto& a : x)
  22. #define pii pair<ll,ll>
  23. #define vi vector<ll>
  24. #define vii vector<pair<ll, ll>>
  25. #define vs vector<string>
  26. #define all(a) (a).begin(),(a).end()
  27. #define F first
  28. #define S second
  29. #define sz(x) (ll)x.size()
  30. #define hell 1000000007
  31. #define lbnd lower_bound
  32. #define ubnd upper_bound
  33. #define max(a,b) (a>b?a:b)
  34. #define min(a,b) (a<b?a:b)
  35.  
  36. /* For Debugging */
  37. #define DEBUG cerr<<"\n>>>I'm Here<<<\n"<<endl;
  38. #define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
  39. #define what_iss(x) cerr << #x << " = " << x << endl;
  40. #define what_is(x) cerr << #x << " = " << x << " ";
  41.  
  42. std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
  43. #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
  44. #define TIME cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
  45. #define DECIMAL(n) cout << fixed ; cout << setprecision(n);
  46. #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  47. using namespace __gnu_pbds;
  48. using namespace std;
  49. #define PI 3.141592653589793
  50. #define N 1005
  51. ll dp[N][N];
  52. ll n,m,r;
  53. ll fact[2*N],modi[2*N];
  54.  
  55. ll add(ll a,ll b,ll mod=hell)
  56. {
  57. return (a+b)%mod;
  58. }
  59. ll sub(ll a,ll b,ll mod=hell)
  60. {
  61. return (a-b+mod)%mod;
  62. }
  63. ll mul(ll a,ll b,ll mod=hell)
  64. {
  65. return (a*b)%mod;
  66. }
  67.  
  68. ll nCr(ll n,ll r) {
  69. if(n<r) {
  70. return 0;
  71. }
  72. return mul(fact[n], mul(modi[r], modi[n-r]));
  73. }
  74.  
  75. ll expo(ll base, ll exponent, ll mod) { //return base^exponent modulo modulus
  76. ll ans = 1;
  77. while(exponent !=0 ) {
  78. if((exponent&1) == 1) {
  79. ans = ans*base ;
  80. ans = ans%mod;
  81. }
  82. base = base*base;
  83. base %= mod;
  84. exponent>>= 1;
  85. }
  86. return ans%mod;
  87. }
  88.  
  89. ll fun(pii p1,pii p2) {
  90. if((p1.F - r > p2.F + r) || (p1.F + r < p2.F - r) || (p1.S - r > p2.S + r) || (p1.S + r < p2.S - r))
  91. return 0;
  92. // what_is(p1.F);
  93. // what_is(p1.S);
  94. // what_is(p2.F);
  95. // what_is(p2.S);
  96. ll x1 = min(max(p1.F+r,p2.F-r), max(p1.F-r,p2.F+r));
  97. ll x2 = max(min(p1.F+r,p2.F-r), min(p1.F-r,p2.F+r));
  98. ll y1 = min(max(p1.S+r,p2.S-r), max(p1.S-r,p2.S+r));
  99. ll y2 = max(min(p1.S+r,p2.S-r), min(p1.S-r,p2.S+r));
  100. // what_is(x1);
  101. // what_is(x2);
  102. // what_is(y1);
  103. // what_iss(y2);
  104. x2 = max(x2 - 1, 0);
  105. y2 = max(y2 - 1, 0);
  106. return (dp[x1][y1] + dp[x2][y2] - dp[x1][y2] - dp[x2][y1]);
  107. }
  108.  
  109.  
  110. void solve()
  111. {
  112. cin >> n >> m >> r;
  113. vector<pair<pii,ll>> v(n);
  114.  
  115. ll nCm = nCr(n,m);
  116.  
  117. rep(i,0,n) {
  118. cin >> v[i].F.F >> v[i].F.S >> v[i].S;
  119. dp[v[i].F.F][v[i].F.S] = 1;
  120. }
  121. rep(i,0,N) {
  122. rep(j,1,N) {
  123. dp[i][j] += dp[i][j-1];
  124. }
  125. }
  126. rep(j,0,N) {
  127. rep(i,1,N) {
  128. dp[i][j] += dp[i-1][j];
  129. }
  130. }
  131. ll ans = 0;
  132. ll k;
  133. rep(i, 0, n) {
  134. rep(j, 0, n) {
  135. k = fun(v[i].F,v[j].F);
  136. // what_is(i);
  137. // what_is(j);
  138. // what_iss(k);
  139. ans = add(ans, mul(sub(nCm, nCr(n - k, m)), mul(v[i].S, v[j].S)));
  140. }
  141. }
  142. cout << ans << endl;
  143. return;
  144. }
  145. int main()
  146. {
  147. fact[0] = 1;
  148. rep(i,1,2*N) {
  149. fact[i] = (fact[i-1] * i) % hell;
  150. }
  151. rep(i,0,2*N) {
  152. modi[i] = expo(fact[i], hell - 2, hell);
  153. }
  154. FAST
  155. int TESTS=1;
  156. // cin>>TESTS;
  157. rep(i,0,TESTS)
  158. {
  159. // cout<<"Case #"<<i+1<<": ";
  160. solve();
  161. }
  162. // TIME
  163. return 0;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment