답안 #735602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
735602 2023-05-04T11:47:16 Z myrcella 이상적인 도시 (IOI12_city) C++17
23 / 100
120 ms 21860 KB
//by szh
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000000
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

const int maxn = 1e5+10;

pii city[maxn];
int ans = 0;
int n;
vector <int> edge[maxn];
int sz[maxn];
map <pii,int> id;
int vis[maxn];

void dfs(int u) {
	vis[u] = 1;
	for (int v:edge[u]) {
		if (vis[v]==1) continue;
		dfs(v);
		sz[u] += sz[v];
	}
//	debug(sz[u]);
	inc(ans,1ll*sz[u]*(n-sz[u])%mod);
}

void solve() {
	memset(vis,0,sizeof(vis));
	rep(i,0,maxn) while (!edge[i].empty()) edge[i].pop_back();
	sort(city,city+n);
	int tot = 0,cnt=1;
	id[city[0]] = 0;
	rep(i,1,n) {
		if (city[i].fi == city[i-1].fi and city[i].se-1 == city[i-1].se) cnt++;
		else sz[tot++] = cnt,cnt = 1;
		id[city[i]] = tot;
		if (id.find(MP(city[i].fi-1,city[i].se))!=id.end()) {
			int tmp = id[MP(city[i].fi-1,city[i].se)];
			edge[tmp].pb(tot);
			edge[tot].pb(tmp);
		}
	}
	sz[tot++] = cnt;
	dfs(0);
}

int DistanceSum(int N, int *X, int *Y) {
	n = N;
	rep(i,0,n) city[i] = {X[i],Y[i]};
	solve();
	rep(i,0,n) swap(city[i].fi,city[i].se);
	solve();
  return ans;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Incorrect 2 ms 3028 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 5620 KB Output is correct
2 Correct 20 ms 6484 KB Output is correct
3 Correct 47 ms 9016 KB Output is correct
4 Correct 53 ms 11460 KB Output is correct
5 Correct 92 ms 13408 KB Output is correct
6 Correct 117 ms 20216 KB Output is correct
7 Correct 104 ms 19764 KB Output is correct
8 Correct 86 ms 13112 KB Output is correct
9 Correct 99 ms 19788 KB Output is correct
10 Correct 120 ms 21860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 6464 KB Output isn't correct
2 Halted 0 ms 0 KB -