# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
304694 |
2020-09-21T17:29:12 Z |
Hehehe |
Ideal city (IOI12_city) |
C++14 |
|
901 ms |
32120 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 |
Correct |
7 ms |
10496 KB |
Output is correct |
2 |
Correct |
8 ms |
10496 KB |
Output is correct |
3 |
Correct |
7 ms |
10496 KB |
Output is correct |
4 |
Correct |
7 ms |
10496 KB |
Output is correct |
5 |
Correct |
7 ms |
10496 KB |
Output is correct |
6 |
Correct |
7 ms |
10496 KB |
Output is correct |
7 |
Correct |
7 ms |
10496 KB |
Output is correct |
8 |
Correct |
7 ms |
10496 KB |
Output is correct |
9 |
Correct |
7 ms |
10496 KB |
Output is correct |
10 |
Correct |
7 ms |
10496 KB |
Output is correct |
11 |
Correct |
7 ms |
10496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
10752 KB |
Output is correct |
2 |
Correct |
9 ms |
10624 KB |
Output is correct |
3 |
Correct |
11 ms |
10880 KB |
Output is correct |
4 |
Correct |
11 ms |
10752 KB |
Output is correct |
5 |
Correct |
14 ms |
11008 KB |
Output is correct |
6 |
Correct |
13 ms |
10752 KB |
Output is correct |
7 |
Correct |
13 ms |
11008 KB |
Output is correct |
8 |
Correct |
13 ms |
10880 KB |
Output is correct |
9 |
Correct |
13 ms |
10752 KB |
Output is correct |
10 |
Correct |
12 ms |
10752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
12276 KB |
Output is correct |
2 |
Correct |
84 ms |
12280 KB |
Output is correct |
3 |
Correct |
241 ms |
14712 KB |
Output is correct |
4 |
Correct |
220 ms |
14840 KB |
Output is correct |
5 |
Incorrect |
613 ms |
18808 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
14968 KB |
Output is correct |
2 |
Correct |
90 ms |
13816 KB |
Output is correct |
3 |
Correct |
382 ms |
21496 KB |
Output is correct |
4 |
Correct |
324 ms |
18648 KB |
Output is correct |
5 |
Incorrect |
901 ms |
32120 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |