Submission #597479

#TimeUsernameProblemLanguageResultExecution timeMemory
597479HanksburgerIdeal city (IOI12_city)C++17
100 / 100
61 ms10672 KiB
#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)

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:49:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |             for (int j=0; j<b[i].size(); j++)
      |                           ~^~~~~~~~~~~~
city.cpp:51:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |                 while (ind<b[i+1].size() && b[i+1][ind].first.second<b[i][j].first.first)
      |                        ~~~^~~~~~~~~~~~~~
city.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |                 while (ind<b[i+1].size() && b[i+1][ind].first.first<=b[i][j].first.second)
      |                        ~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...