Submission #134615

# Submission time Handle Problem Language Result Execution time Memory
134615 2019-07-23T05:39:02 Z sealnot123 Ideal city (IOI12_city) C++14
0 / 100
1000 ms 262148 KB

#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef double D;
typedef long double LD;
const int N = 100005;
vector<int> compx, compy;
int lastx[N], lasty[N];
int orderx[N], ordery[N];
vector<int> g[N];
LL ans;
LL dp[N], sz[N];
int n;
int *XX, *YY;

void add_edge(int a, int b){
	g[a].pb(b); g[b].pb(a);
}

bool cmpx(int a, int b){
	return XX[a] < XX[b];
}

bool cmpy(int a, int b){
	return YY[a] < YY[b];
}

void dfs(int u, int v){
	/*printf("%d\n",u);*/
	sz[u] = 1;
	for(int e : g[u]){
		if(e == v) continue;
		dfs(e, u);
		ans += (dp[e]+sz[e])*sz[u] + dp[u]*sz[e];
		dp[u] += dp[e] + sz[e];
		sz[u] += sz[e];
	}
}

int DistanceSum(int nn, int *X, int *Y) {
	printf("asdsdada");
	n = nn;
	XX = X;
	YY = Y;
	int i,j,k,l,a,b,c,d;
	for(i=0;i<n;i++) compx.pb(X[i]), compy.pb(Y[i]);
	sort(all(compx)); sort(all(compy));
	compx.erase(unique(all(compx)), compx.end());
	compy.erase(unique(all(compy)), compy.end());
	for(i=0;i<n;i++) orderx[i] = ordery[i] = i;
	sort(orderx,orderx+n,cmpx);
	sort(ordery,ordery+n,cmpy);
	memset(lastx, -1, sizeof lastx);
	memset(lasty, -1, sizeof lasty);
	for(i = 0; i < n; i++){
		b = orderx[i];
		printf("%d ",b);
		c = lower_bound(all(compx), X[b]) - compx.begin();
		a = lower_bound(all(compy), Y[b]) - compy.begin();
		if(lasty[a] != -1) add_edge(lasty[a], c);
		lasty[a] = c;
	}
	printf("\n");
	dfs(0,0);
	for(i=0;i<n;i++) g[i].clear();
	memset(dp, 0, sizeof dp);
	memset(sz, 0, sizeof sz);
	for(i = 0; i < n; i++){
		b = ordery[i];
		printf("%d ",b);
		c = lower_bound(all(compy), Y[b]) - compy.begin();
		a = lower_bound(all(compx), X[b]) - compx.begin();
		if(lastx[a] != -1) add_edge(lastx[a], c);
		lastx[a] = c;
	}
	printf("\n");
	dfs(0,0);
  	return ans;
}
/*
4
0 0
0 1
0 2
0 3
(10)
*/

Compilation message

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:55:8: warning: unused variable 'j' [-Wunused-variable]
  int i,j,k,l,a,b,c,d;
        ^
city.cpp:55:10: warning: unused variable 'k' [-Wunused-variable]
  int i,j,k,l,a,b,c,d;
          ^
city.cpp:55:12: warning: unused variable 'l' [-Wunused-variable]
  int i,j,k,l,a,b,c,d;
            ^
city.cpp:55:20: warning: unused variable 'd' [-Wunused-variable]
  int i,j,k,l,a,b,c,d;
                    ^
# Verdict Execution time Memory Grader output
1 Runtime error 273 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 408 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 4600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 250 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -