Submission #735630

# Submission time Handle Problem Language Result Execution time Memory
735630 2023-05-04T12:18:30 Z myrcella Ideal city (IOI12_city) C++17
32 / 100
4 ms 852 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 = 1e3+10;

pii city[maxn];
int ans = 0;
int n;
vector <int> edge[maxn];
int sz[maxn];
map <pii,int> id;
int vis[maxn];
int dis[maxn][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();
	id.clear();
	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();
//	debug(ans);
	rep(i,0,n) swap(city[i].fi,city[i].se);
	solve();
  return ans;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -