# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
316922 |
2020-10-28T15:28:20 Z |
tengiz05 |
Ideal city (IOI12_city) |
C++17 |
|
1000 ms |
54600 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e5+5, mod = 1e9;
ll x[N], y[N], n;
ll d1[4] = {0, 0, 1, -1};
ll d2[4] = {1,-1, 0, 0};
vector<int> edges[N];
int DistanceSum(int NN, int *X, int *Y) {
n = NN;
map<pair<int, int>, bool> used, m, road;
map<pair<int, int>, int> r;
for(int i=0;i<n;i++){
x[i] = X[i], y[i] = Y[i];
m[{x[i], y[i]}] = true;
r[{x[i], y[i]}] = i;
}
queue<tuple<int, int, int>> Q;
Q.push(make_tuple(x[0], y[0], 0));
used[{x[0], y[0]}] = true;
while(!Q.empty()){
auto P = Q.front();Q.pop();
int f, s, node;
tie(f, s, node) = P;
for(int i=0;i<4;i++){
int nf = f+d1[i], ns = s+d2[i];
if(!m[{nf, ns}])continue;
if(!road[{node, r[{nf, ns}]}]){
edges[node].push_back(r[{nf,ns}]);
edges[r[{nf,ns}]].push_back(node);
road[{node, r[{nf, ns}]}] = true;
road[{r[{nf, ns}], node}] = true;
}else continue;
if(!used[{nf, ns}]){
Q.push(make_tuple(nf, ns, r[{nf, ns}]));
}used[{nf, ns}] = true;
}
}
// for(int i=0;i<n;i++){cout << i << ": ";for(auto x : edges[i])cout << x << ' ';cout << '\n';}cout << "\n\n";
ll ans = 0;
if(n <= 3000){
for(int p=0;p<n;p++){
queue<int> q;
q.push(p);
vector<int> dist(n, mod*2);dist[p] = 0;
while(!q.empty()){
int u=q.front();q.pop();
for(auto v : edges[u]){
if(dist[u]+1 < dist[v]){
dist[v] = dist[u]+1;
q.push(v);
}
}
}for(int i=p+1;i<n;i++)ans += dist[i], ans %= mod;
}
}else {
sort(x, x+n);
sort(y, y+n);
vector<ll> sx(n+1), sy(n+1);
for(int i=n-1;i>=0;i--){
sx[i] = sx[i+1]+x[i];
sy[i] = sy[i+1]+y[i];
}for(int i=0;i<n-1;i++){
ll t = x[i]*(n-i-1);
ans += (sx[i+1]-t)%mod;ans %= mod;
t = y[i]*(n-i-1);
ans += (sy[i+1]-t)%mod;ans %= mod;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2724 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2688 KB |
Output is correct |
5 |
Correct |
3 ms |
2688 KB |
Output is correct |
6 |
Correct |
4 ms |
2816 KB |
Output is correct |
7 |
Correct |
4 ms |
2816 KB |
Output is correct |
8 |
Correct |
4 ms |
2816 KB |
Output is correct |
9 |
Correct |
5 ms |
2816 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
4 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
3200 KB |
Output is correct |
2 |
Correct |
35 ms |
3200 KB |
Output is correct |
3 |
Correct |
73 ms |
3328 KB |
Output is correct |
4 |
Correct |
77 ms |
3448 KB |
Output is correct |
5 |
Correct |
125 ms |
3584 KB |
Output is correct |
6 |
Correct |
124 ms |
3712 KB |
Output is correct |
7 |
Correct |
150 ms |
3584 KB |
Output is correct |
8 |
Correct |
125 ms |
3712 KB |
Output is correct |
9 |
Correct |
123 ms |
3712 KB |
Output is correct |
10 |
Correct |
122 ms |
3716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
13048 KB |
Output is correct |
2 |
Correct |
146 ms |
13048 KB |
Output is correct |
3 |
Correct |
441 ms |
28536 KB |
Output is correct |
4 |
Correct |
418 ms |
28664 KB |
Output is correct |
5 |
Correct |
965 ms |
54456 KB |
Output is correct |
6 |
Correct |
950 ms |
54300 KB |
Output is correct |
7 |
Correct |
902 ms |
54600 KB |
Output is correct |
8 |
Execution timed out |
1022 ms |
54392 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
120 ms |
12244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |