# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
597479 | Hanksburger | Ideal city (IOI12_city) | C++17 | 61 ms | 10672 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > b[100005];
vector<int> adj[100005], w;
vector<pair<int, int> > a;
long long ans;
int n;
long long dfs(int u, int p)
{
long long sum=w[u];
for (int v:adj[u])
{
if (v!=p)
{
long long x=dfs(v, u);
ans=(ans+x*(n-x))%1000000000;
sum+=x;
}
}
return sum;
}
int DistanceSum(int N, int *X, int *Y)
{
n=N;
for (int z=0; z<2; z++)
{
int mn=2147483647, sz=0, cnt=0;
for (int i=0; i<n; i++)
{
mn=min(mn, X[i]);
sz=max(sz, X[i]);
}
sz-=mn;
for (int i=0; i<n; i++)
a.push_back({X[i]-mn, Y[i]});
sort(a.begin(), a.end());
for (int i=0; i<n; )
{
int ind=i+1;
while (ind<n && a[i].first==a[ind].first && a[ind-1].second+1==a[ind].second)
ind++;
w.push_back(a[ind-1].second-a[i].second+1);
b[a[i].first].push_back({{a[i].second, a[ind-1].second}, cnt++});
i=ind;
}
for (int i=0; i<sz; i++)
{
int ind=0;
for (int j=0; j<b[i].size(); j++)
{
while (ind<b[i+1].size() && b[i+1][ind].first.second<b[i][j].first.first)
ind++;
while (ind<b[i+1].size() && b[i+1][ind].first.first<=b[i][j].first.second)
{
int u=b[i][j].second, v=b[i+1][ind].second;
adj[u].push_back(v);
adj[v].push_back(u);
ind++;
}
ind=max(0, ind-1);
}
}
dfs(0, 0);
for (int i=0; i<n; i++)
swap(X[i], Y[i]);
a.clear();
w.clear();
for (int i=0; i<=sz; i++)
b[i].clear();
for (int i=0; i<cnt; i++)
adj[i].clear();
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |