#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define F first
#define S second
#define MP make_pair
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
const int MOD=1e9;
vector<int> G[100005];
bitset<100005> vis;
unordered_map<ll,int> mp;
int DistanceSum(int N, int *X, int *Y)
{
int ans=0;
for(int i=0;i<N;++i)
mp[(ll)X[i]<<31|Y[i]]=i;
for(int i=0;i<N;++i)
for(int j=0;j<4;++j)
{
auto p=mp.find(((ll)(X[i]+dx[j])<<31)|(Y[i]+dy[j]));
if(p!=mp.end()) G[i].pb(p->S);
}
for(int i=0;i<N;++i)
{
int tp=0;
queue<pii> q;
q.push(MP(i,0)),vis.reset(),vis[i]=1;
while(!q.empty())
{
auto tmp=q.front();
q.pop(),ans=(ans+tmp.S)%MOD,vis[tmp.F]=1;
for(int j:G[tmp.F])
if(!vis[j]) q.push(MP(j,tmp.S+1)),vis[j]=1;
++tp;
}
}
return ans/2;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2816 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
3 |
Correct |
4 ms |
2688 KB |
Output is correct |
4 |
Correct |
4 ms |
2688 KB |
Output is correct |
5 |
Correct |
5 ms |
2688 KB |
Output is correct |
6 |
Correct |
5 ms |
2688 KB |
Output is correct |
7 |
Correct |
5 ms |
2688 KB |
Output is correct |
8 |
Correct |
5 ms |
2688 KB |
Output is correct |
9 |
Correct |
5 ms |
2688 KB |
Output is correct |
10 |
Correct |
5 ms |
2688 KB |
Output is correct |
11 |
Correct |
5 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
2816 KB |
Output is correct |
2 |
Correct |
28 ms |
2816 KB |
Output is correct |
3 |
Correct |
62 ms |
2816 KB |
Output is correct |
4 |
Correct |
65 ms |
2876 KB |
Output is correct |
5 |
Correct |
110 ms |
2940 KB |
Output is correct |
6 |
Correct |
92 ms |
2936 KB |
Output is correct |
7 |
Correct |
106 ms |
2916 KB |
Output is correct |
8 |
Correct |
95 ms |
2912 KB |
Output is correct |
9 |
Correct |
93 ms |
2908 KB |
Output is correct |
10 |
Correct |
87 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1077 ms |
4480 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1071 ms |
4472 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |