# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
66041 |
2018-08-09T12:55:12 Z |
mhnd |
Ideal city (IOI12_city) |
C++14 |
|
263 ms |
32592 KB |
//#include "grader.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 5e5+50;
const ll oo = 1e18;
const ll mod = 1e9;
int cost[2010][2010],r[2010][2010];
ll ans = 0;
int cur;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
void bfs(pair<int,int> st){
queue<pair<int,int>> q;
q.push(st);
int fr = r[st.first][st.second];
cost[fr][fr] = 0;
while(q.size()){
pair<int,int> u = q.front();
q.pop();
int bf = r[u.first][u.second];
if(fr < bf)ans += cost[fr][bf];
for(int i=0;i<4;i++){
pair<int,int> v = {u.first+dx[i],u.second+dy[i]};
int idx = r[v.first][v.second];
if(idx==-1 || cost[fr][idx]!=-1)continue;
cost[fr][idx] = cost[fr][bf]+1;
q.push(v);
}
}
}
int DistanceSum(int N, int *X, int *Y) {
if(N<=2000){
int mn1 = *min_element(X, X+N), mn2 = *min_element(Y, Y+N);
mn1-=5;
mn2-=5;
memset(cost,-1,sizeof(cost));
memset(r,-1,sizeof(r));
for(int i=0;i<N;i++){
X[i]-=mn1;
Y[i]-=mn2;
r[X[i]][Y[i]]=i;
}
for(int i=0;i<N;i++)bfs({X[i],Y[i]});
return ans;
}
sort(X,X+N);
int sum=0,ret=0,lst=X[0];
for(int i=0;i<N;i++){
if(X[i]!=lst){
ret = (ret + (X[i]-lst)*1ll*(sum*1ll*(N-sum))%mod)%mod;
lst = X[i];
}
sum++;
}
ans = ret;
sort(Y,Y+N);
sum=0;ret=0;lst=Y[0];
for(int i=0;i<N;i++){
if(Y[i]!=lst){
ret = (ret + (Y[i]-lst)*1ll*(sum*1ll*(N-sum))%mod)%mod;
lst = Y[i];
}
sum++;
}
ans = (ans+ret)%mod;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
31944 KB |
Output is correct |
2 |
Correct |
27 ms |
31972 KB |
Output is correct |
3 |
Correct |
28 ms |
32084 KB |
Output is correct |
4 |
Correct |
27 ms |
32088 KB |
Output is correct |
5 |
Correct |
27 ms |
32256 KB |
Output is correct |
6 |
Correct |
30 ms |
32256 KB |
Output is correct |
7 |
Correct |
30 ms |
32288 KB |
Output is correct |
8 |
Correct |
29 ms |
32288 KB |
Output is correct |
9 |
Correct |
28 ms |
32288 KB |
Output is correct |
10 |
Correct |
36 ms |
32288 KB |
Output is correct |
11 |
Correct |
31 ms |
32288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
32336 KB |
Output is correct |
2 |
Correct |
67 ms |
32340 KB |
Output is correct |
3 |
Correct |
157 ms |
32340 KB |
Output is correct |
4 |
Correct |
124 ms |
32364 KB |
Output is correct |
5 |
Correct |
243 ms |
32564 KB |
Output is correct |
6 |
Correct |
218 ms |
32564 KB |
Output is correct |
7 |
Correct |
263 ms |
32564 KB |
Output is correct |
8 |
Correct |
249 ms |
32580 KB |
Output is correct |
9 |
Correct |
182 ms |
32592 KB |
Output is correct |
10 |
Correct |
176 ms |
32592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
32592 KB |
Output is correct |
2 |
Correct |
8 ms |
32592 KB |
Output is correct |
3 |
Correct |
17 ms |
32592 KB |
Output is correct |
4 |
Correct |
18 ms |
32592 KB |
Output is correct |
5 |
Correct |
34 ms |
32592 KB |
Output is correct |
6 |
Correct |
35 ms |
32592 KB |
Output is correct |
7 |
Correct |
36 ms |
32592 KB |
Output is correct |
8 |
Correct |
43 ms |
32592 KB |
Output is correct |
9 |
Correct |
35 ms |
32592 KB |
Output is correct |
10 |
Correct |
41 ms |
32592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
32592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |