# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
18841 |
2016-02-15T23:27:22 Z |
ggoh |
Ideal city (IOI12_city) |
C++ |
|
206 ms |
22724 KB |
#include<cstdio>
#include<map>
#include<queue>
int a,x,y,p,q,i,j,dx[]={1,0,-1,0},dy[]={0,1,0,-1};
long long sum,mod=1e9;
bool m[2002][2002];
std::queue<int>P,Q;
int DistanceSum (int N, int *X, int *Y)
{
a=N;
x=2147483647;y=2147483647;
for(i=0;i<a;i++)x=std::min(x,X[i]),y=std::min(y,Y[i]);
for(i=0;i<a;i++)X[i]-=x,Y[i]-=y,m[X[i]][Y[i]]=1;
if(a<=2000)
{
int D[2002][2002];
for(i=0;i<a;i++)
{
P.push(X[i]);
Q.push(Y[i]);
for(j=0;j<a;j++)D[X[j]][Y[j]]=0;
D[X[i]][Y[i]]=1;sum++;
while(!P.empty())
{
p=P.front();P.pop();q=Q.front();Q.pop();
for(int k=0;k<4;k++)
{
x=p+dx[k];y=q+dy[k];
if(x>=0&&y>=0&&m[x][y]&&D[x][y]==0)
{
D[x][y]=D[p][q]+1;
sum+=D[x][y];
P.push(x);Q.push(y);
}
}
}
sum-=a;
}
sum/=(long long)2;
}
else
{
long long xsum[100002]={},ysum[100002]={};
long long xx,yy;
for(i=0;i<a;i++)
{
xsum[X[i]]++;ysum[Y[i]]++;
}
xx=xsum[0];yy=ysum[0];
for(i=1;i<a;i++)
{
sum+=xx*(long long)xsum[i];
xsum[i]+=xsum[i-1];
xx+=xsum[i];
sum+=yy*(long long)ysum[i];
ysum[i]+=ysum[i-1];
yy+=ysum[i];
}
}
return sum%mod;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
21156 KB |
Output is correct |
2 |
Correct |
0 ms |
21936 KB |
Output is correct |
3 |
Correct |
0 ms |
21936 KB |
Output is correct |
4 |
Correct |
0 ms |
21940 KB |
Output is correct |
5 |
Correct |
0 ms |
21936 KB |
Output is correct |
6 |
Correct |
0 ms |
21932 KB |
Output is correct |
7 |
Correct |
0 ms |
21940 KB |
Output is correct |
8 |
Correct |
2 ms |
21940 KB |
Output is correct |
9 |
Correct |
2 ms |
21932 KB |
Output is correct |
10 |
Correct |
2 ms |
21936 KB |
Output is correct |
11 |
Correct |
0 ms |
21940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
21936 KB |
Output is correct |
2 |
Correct |
39 ms |
21936 KB |
Output is correct |
3 |
Correct |
108 ms |
21936 KB |
Output is correct |
4 |
Correct |
91 ms |
21936 KB |
Output is correct |
5 |
Correct |
197 ms |
21940 KB |
Output is correct |
6 |
Correct |
144 ms |
21940 KB |
Output is correct |
7 |
Correct |
206 ms |
21936 KB |
Output is correct |
8 |
Correct |
143 ms |
21936 KB |
Output is correct |
9 |
Correct |
134 ms |
21936 KB |
Output is correct |
10 |
Correct |
133 ms |
21940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
22096 KB |
Output is correct |
2 |
Correct |
7 ms |
22092 KB |
Output is correct |
3 |
Correct |
13 ms |
22328 KB |
Output is correct |
4 |
Correct |
8 ms |
22328 KB |
Output is correct |
5 |
Correct |
21 ms |
22724 KB |
Output is correct |
6 |
Correct |
12 ms |
22724 KB |
Output is correct |
7 |
Correct |
19 ms |
22720 KB |
Output is correct |
8 |
Correct |
19 ms |
22724 KB |
Output is correct |
9 |
Runtime error |
21 ms |
6408 KB |
SIGSEGV Segmentation fault |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
22092 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |