# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
18834 |
2016-02-15T23:07:43 Z |
ggoh |
Ideal city (IOI12_city) |
C++ |
|
1000 ms |
262144 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;
std::map<int,int>m[2002],D[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;
for(i=0;i<a;i++)
{
P.push(X[i]);
Q.push(Y[i]);
D[i][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[i][x][y]==0)
{
D[i][x][y]=D[i][p][q]+1;
sum+=D[i][x][y];
P.push(x);Q.push(y);
}
}
}
sum-=a;
}
sum/=(long long)2;
return sum%mod;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
189680 KB |
Output is correct |
2 |
Correct |
65 ms |
189680 KB |
Output is correct |
3 |
Correct |
24 ms |
189680 KB |
Output is correct |
4 |
Correct |
39 ms |
190076 KB |
Output is correct |
5 |
Correct |
59 ms |
190076 KB |
Output is correct |
6 |
Correct |
67 ms |
191528 KB |
Output is correct |
7 |
Correct |
67 ms |
191528 KB |
Output is correct |
8 |
Correct |
49 ms |
191528 KB |
Output is correct |
9 |
Correct |
63 ms |
191528 KB |
Output is correct |
10 |
Correct |
57 ms |
191528 KB |
Output is correct |
11 |
Correct |
71 ms |
191528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
567 ms |
236540 KB |
Output is correct |
2 |
Correct |
546 ms |
236540 KB |
Output is correct |
3 |
Memory limit exceeded |
793 ms |
262144 KB |
Memory limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1000 ms |
262144 KB |
Program timed out |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1000 ms |
262144 KB |
Program timed out |
2 |
Halted |
0 ms |
0 KB |
- |