Submission #173597

# Submission time Handle Problem Language Result Execution time Memory
173597 2020-01-04T16:56:40 Z groeneprof Ideal city (IOI12_city) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define int long long
#define P(x) do {if(debug) cout << x << endl;} while(false)
#define H(x) P(#x << ": " << x)
#define FR(i, a, b) for(int i = (a); i < (b); ++i)
#define F(i, n) FR(i, 0, n)
#define DR(i, a, b) for(int i = (b); i --> (a);)
#define D(i, n) DR(i, 0, n)
#define S(s) (int)(s).size()
#define ALL(x) (x).begin(), (x).end()
#define MI(x, a) (x) = min(x, a)
#define MA(x, a) (x) = max(x, a)
#define V vector
#define pb push_back
#define mp make_pair
using namespace std;
const bool debug = 1;
const int inf = 1e18;
const int mod = 1e9;

vector<vector<int> > graph;
vector<int> sd, nn;

void dfs1(int u, int par){
	for(int v : graph[u]) if(v!=par){
		dfs1(v, u);
		nn[u] = (nn[u] + nn[v]);
		sd[u] = (sd[u] + sd[v] + nn[v]);
	}
}

int tot;

void dfs2(int u, int par, int sdpar, int nnpar){
	tot += sd[u] + sdpar + nnpar;
	for(int v : graph[u]) if(v!=par){
		dfs2(v, u, sdpar+nnpar+sd[u]-sd[v]-nn[v], nnpar+nn[u]-nn[v]);
	}
}

int calc(int N,vector<int>& x, vector<int>& y){
	map<pair<int,int>, int> mpa;
	vector<pair<int,int> > v(N);
	F(i, N){
		v[i] = mp(x[i], y[i]);
		mpa[v[i]] = i;
	}
	sort(v.begin(), v.end());
	graph = { {  } };
	vector<int> part(N);
	int j = 0;
	for(int i = 0; i<N; i++){
		if(i>0 && v[i-1] != mp(v[i].first,v[i].second-1)){
			j++;
			graph.resize(graph.size()+1);
		}
		part[mpa[v[i]]] = j;
		int a = 0;
		if(mpa.count({v[i].first-1,v[i].second})){
			if(!(graph[j].size()>=1 && graph[j][graph[j].size()-1] != part[mpa[mp(v[i].first-1,v[i].second)]]) 
			&& !(graph[j].size()>=2 && graph[j][graph[j].size()-2] != part[mpa[mp(v[i].first-1,v[i].second)]]) ){
				graph[j].push_back(part[mpa[mp(v[i].first-1,v[i].second)]]);
			}
			a=1;
		}
		if(mpa.count({v[i].first+1,v[i].second})){
			if(!(graph[j].size()>=1+a && graph[j][graph[j].size()-1-a] != part[mpa[mp(v[i].first+1,v[i].second)]]) 
			&& !(graph[j].size()>=2+a && graph[j][graph[j].size()-2-a] != part[mpa[mp(v[i].first+1,v[i].second)]]) ){
				graph[j].push_back(part[mpa[mp(v[i].first+1,v[i].second)]]);
			}
		}
	}
	sd.assign(graph.size(),0);
	nn.assign(graph.size(),1);
	tot = 0;
	dfs1(0,0);
	dfs2(0,0,0,0);
	return tot/2;
}

int DistanceSum(int N, int *X, int *Y) {
	vector<int> x(N), y(N);
	F(i,N){
		x[i] = X[i];
		y[i] = Y[i];
	}
	return calc(N, x, y) + calc(N, y, x);
}

Compilation message

city.cpp: In function 'long long int calc(long long int, std::vector<long long int>&, std::vector<long long int>&)':
city.cpp:67:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(!(graph[j].size()>=1+a && graph[j][graph[j].size()-1-a] != part[mpa[mp(v[i].first+1,v[i].second)]]) 
         ~~~~~~~~~~~~~~~^~~~~
city.cpp:68:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    && !(graph[j].size()>=2+a && graph[j][graph[j].size()-2-a] != part[mpa[mp(v[i].first+1,v[i].second)]]) ){
         ~~~~~~~~~~~~~~~^~~~~
/tmp/ccGxTrLq.o: In function `main':
grader.cpp:(.text.startup+0xf1): undefined reference to `DistanceSum(int, int*, int*)'
collect2: error: ld returned 1 exit status