# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
304690 |
2020-09-21T17:28:20 Z |
Hehehe |
Ideal city (IOI12_city) |
C++14 |
|
108 ms |
14968 KB |
#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define sz(x) (int)((x).size())
//#define int long long
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const ll inf = 2e9;
const ll mod = 1e9 + 0;
const int N = 1e5 + 11;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);
//ifstream in(".in");
//ofstream out(".out");
pi v[N];
int comp[N], siz[N], siz1[N], sum[N], sum1[N], viz[N], k;
map<pi, int> a;
set<int> g[N], g1[N];
void dfs(int nod, int p){
sum[nod] = siz[nod];
for(auto it : g[nod])
if(it != p){
dfs(it, nod);
sum[nod] += sum[it];
}
}
void dfs1(int nod, int p){
sum1[nod] = siz1[nod];
for(auto it : g1[nod])
if(it != p){
dfs1(it, nod);
sum1[nod] += sum1[it];
}
}
int DistanceSum (int n, int *X, int *Y){
for(int i = 1; i <= n; i++){
v[i] = {X[i - 1], Y[i - 1]};
a[v[i]] = i;
}
//horizontal
for(int i = 1; i <= n; i++){
if(viz[i])continue;
viz[i] = 1;
comp[i] = ++k;
int cnt = 0;
int x = X[i - 1], y = Y[i - 1];
while(a[{x, y + 1}]){
y++;
int idx = a[{x, y}];
comp[idx] = k;
viz[idx] = 1;
cnt++;
}
y = Y[i - 1];
while(a[{x, y - 1}]){
y--;
int idx = a[{x, y}];
comp[idx] = k;
viz[idx] = 1;
cnt++;
}
siz[k] = cnt;
}
for(int i = 1; i <= n; i++){
int I = X[i - 1], J = Y[i - 1];
int now = comp[i];
for(int l = 0; l < 4; l++){
int x = I + dx[l], y = J + dy[l];
if(!a[{x, y}])continue;
int next = comp[a[{x, y}]];
if(now == next)continue;
g[now].insert(next);
g[next].insert(now);
}
}
dfs(1, 0);
int ans = 0;
for(int i = 1; i <= k; i++){
ans = (ans + sum[i] * (n - sum[i]) + mod) % mod;
}
k = 0;
memset(viz, 0, sizeof(viz));
memset(comp, 0, sizeof(comp));
//vertical
for(int i = 1; i <= n; i++){
if(viz[i])continue;
viz[i] = 1;
comp[i] = ++k;
int cnt = 0;
int x = X[i - 1], y = Y[i - 1];
while(a[{x + 1, y}]){
x++;
int idx = a[{x, y}];
comp[idx] = k;
viz[idx] = 1;
cnt++;
}
x = X[i - 1];
while(a[{x - 1, y}]){
x--;
int idx = a[{x, y}];
comp[idx] = k;
viz[idx] = 1;
cnt++;
}
siz1[k] = cnt;
}
for(int i = 1; i <= n; i++){
int I = X[i - 1], J = Y[i - 1];
int now = comp[i];
for(int l = 0; l < 4; l++){
int x = I + dx[l], y = J + dy[l];
if(!a[{x, y}])continue;
int next = comp[a[{x, y}]];
if(now == next)continue;
g1[now].insert(next);
g1[next].insert(now);
}
}
dfs1(1, 0);
for(int i = 1; i <= k; i++){
ans = (ans + sum1[i] * (n - sum1[i]) + mod) % mod;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
10496 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
10752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
82 ms |
12280 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
108 ms |
14968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |