답안 #174694

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
174694 2020-01-06T17:46:21 Z groeneprof 이상적인 도시 (IOI12_city) C++14
32 / 100
43 ms 3484 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 = 0;
const int inf = 1e18;
const int mod = 1e9;

vector<vector<int> > graph;
vector<int> parts;
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){
	H(u); H(par); H(nn[u]); H(sd[u]); H(sdpar); H(nnpar); H(sd[u] + sdpar + nnpar);
	tot += parts[u]*(sd[u] + sdpar + nnpar);
	sdpar+=nnpar;
	for(int v : graph[u]) if(v!=par){
		dfs2(v, u, sdpar+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);
	parts = {0};
	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);
			parts.push_back(0);
		}
		part[mpa[v[i]]] = j;
		parts[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)]]);
				graph[part[mpa[mp(v[i].first-1,v[i].second)]]].push_back(j);
			}
			//a=1;
		}
		
	}
	/*for(int i = 0; i<graph.size(); i++){
		for(int j : graph[i]){
			cout<<j<<" ";
		}
		cout<<endl;
	}*/
	sd.assign(graph.size(),0);
	nn = parts;
	tot = 0;
	dfs1(0,0);
	dfs2(0,0,0,0);
	return tot/2;
}

int DistanceSum(signed N, signed *X, signed *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:64:7: warning: unused variable 'a' [-Wunused-variable]
   int a = 0;
       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 4 ms 508 KB Output is correct
5 Correct 5 ms 632 KB Output is correct
6 Correct 5 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 528 KB Output is correct
10 Correct 5 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 3484 KB Output isn't correct
2 Halted 0 ms 0 KB -