Submission #575534

#TimeUsernameProblemLanguageResultExecution timeMemory
575534FatihSolakIdeal city (IOI12_city)C++17
0 / 100
1084 ms7312 KiB
#include <bits/stdc++.h> #define N 100005 using namespace std; const int mod = 1e9; long long ans = 0; int group[N]; vector<int> adj[N]; int sz[N]; int sub[N]; vector<int> v[N]; int n; void dfs(int v,int par){ sub[v] = sz[v]; for(auto u:adj[v]){ if(u == par)continue; //cout << v << " edge " << u << endl; dfs(u,v); sub[v] += sub[u]; ans += (long long)sub[u]*(n-sub[u]); } } void solve(){ int cnt = 1; int bef = 1; for(int i = 0;i<n;i++){ int tmp = cnt; sort(v[i].begin(),v[i].end()); for(int j = 0;j<v[i].size();j++){ sz[cnt] = 0; int r = j-1; bool last = 0; while(r + 1< v[i].size() && v[i][j] + (r-j+1) == v[i][r+1]){ r++; //cout << v[i][r] << " "; if(last == 0 && bef <= group[v[i][r]]){ adj[group[v[i][r]]].push_back(cnt); adj[cnt].push_back(group[v[i][r]]); last = 1; } else last = 0; sz[cnt]++; group[v[i][r]] = cnt; } //cout << endl; j = r; cnt++; } bef = tmp; } dfs(1,0); } int DistanceSum(int n_, int *x, int *y) { n = n_; vector<int> compressx,compressy; for(int i = 0;i<n;i++){ compressx.push_back(x[i]); compressy.push_back(y[i]); } sort(compressx.begin(),compressx.end()); sort(compressy.begin(),compressy.end()); compressx.resize(unique(compressx.begin(),compressx.end())-compressx.begin()); compressy.resize(unique(compressy.begin(),compressy.end())-compressy.begin()); map<pair<int,int>,int> mp; for(int i = 0;i<n;i++){ x[i] = lower_bound(compressx.begin(),compressx.end(),x[i]) - compressx.begin(); y[i] = lower_bound(compressy.begin(),compressy.end(),y[i]) - compressy.begin(); mp[{x[i],y[i]}] = 1; } for(int i = 0;i<n;i++){ v[x[i]].push_back(y[i]); } solve(); for(int i = 0;i<n;i++){ v[i].clear(); adj[i].clear(); group[i] = 0; } for(int i = 0;i<n;i++){ v[y[i]].push_back(x[i]); } solve(); return ans%mod; }

Compilation message (stderr)

city.cpp: In function 'void solve()':
city.cpp:28:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for(int j = 0;j<v[i].size();j++){
      |                       ~^~~~~~~~~~~~
city.cpp:32:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |             while(r  + 1< v[i].size() && v[i][j] + (r-j+1) == v[i][r+1]){
      |                   ~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...