Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- #define sz(s) (int)(s).size()
- #define all(s) s.begin(), s.end()
- void Speed(){
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- }
- const int mod = 1e9 + 7;
- ll power(ll a, ll n)
- {
- if(!n)
- return 1;
- ll res = power(a , n / 2);
- res = res * res % mod;
- if(n & 1)
- res = res * a % mod;
- return res;
- }
- void solve(){
- vector<vector<ll>> arr(3 , vector<ll>(3));
- for(int i = 0; i < 3; i++)
- cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
- vector<vector<pair<ll,ll>>> a(3);
- for(int j = 0; j < 3; j++){
- for(ll x = arr[j][0] - arr[j][2]; x <= arr[j][0] + arr[j][2]; x++){
- for(ll y = arr[j][1] - arr[j][2]; y <= arr[j][1] + arr[j][2]; y++){
- if((x - arr[j][0]) * (x - arr[j][0]) + (y - arr[j][1]) * (y - arr[j][1]) > arr[j][2] * arr[j][2])
- continue;
- a[j].push_back({x,y});
- }
- }
- }
- vector<int> inds = {0,1,2};
- ll num = 0 , denum = 0;
- do{
- int f = inds[0] , s = inds[1] , t = inds[2];
- map<ll,pair<ll,ll>> mp_x , mp_y;
- for(auto& [x,y] : a[s]){
- mp_x[x].first++;
- mp_x[x].second += y;
- // mp_x[x].second %= mod;
- }
- for(auto& [x,y] : a[t]){
- mp_y[y].first++;
- mp_y[y].second += x;
- // mp_y[y].second %= mod;
- }
- for(auto&[x,y] : a[f]){
- auto p_x = mp_x[x];
- auto p_y = mp_y[y];
- ll d_y = abs(p_x.second - p_x.first * y) % mod;
- ll d_x = abs(p_y.second - p_y.first * x) % mod;
- num += d_x * d_y % mod;
- num %= mod;
- denum += p_x.first * p_y.first % mod;
- denum %= mod;
- }
- }while(next_permutation(all(inds)));
- denum = denum * 2 % mod;
- ll ans = num * power(denum , mod - 2) % mod;
- cout << ans << "\n";
- }
- int main(){
- freopen("triangle.in", "r", stdin);
- Speed();
- int tc = 1;
- // cin >> tc;
- while (tc--){
- solve();
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment