#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 2e9+5
#define eps 1e-7
#define eps1 1e-25
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
#define V 450
using namespace std;
const int MOD = 1e9;
const int nax = 1e5+5;
int ans = 0;
int mnx = INF,mny = INF, mxx = 0, mxy = 0;
int mov[4][2] = {{1,0},{0,1},{-1,0},{0,-1}}, d[nax];
bool vis[nax],grid[nax];
int DistanceSum(int n, int *x, int *y) {
for (int i = 0; i < n; ++i)
{
mnx = min(mnx,x[i]), mny = min(mny,y[i]);
mxx = max(mxx,x[i]), mxy = max(mxy, y[i]);
}
mxx-=mnx,mxy-=mny;
mxx++,mxy++;
assert(mxx*mxy<=1e4);
for (int i = 0; i < n; ++i)
{
x[i]-=mnx,y[i]-=mny;
grid[x[i]*mxy+y[i]] = 1;
}
for (int i = 0; i < n; ++i)
{
queue<ii> q;
q.push({x[i], y[i]});
memset(d,0,sizeof d);
vis[x[i]*mxy + y[i]] = 1;
while(!q.empty()){
int x1 = q.front().fi , y1 = q.front().se;
q.pop();
for (int j = 0; j < 4; ++j)
{
int nx = x1 + mov[j][0], ny = y1 + mov[j][1];
if(nx < 0 || ny < 0 || nx >= mxx || ny >= mxy || !grid[nx*mxy+ny] || d[nx*mxy + ny] ) continue;
d[nx*mxy + ny] = d[x1*mxy + y1] + 1;
if(!vis[nx*mxy + ny])
ans += d[nx*mxy + ny];
ans %= MOD;
q.push({nx,ny});
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
4 ms |
596 KB |
Output is correct |
7 |
Correct |
4 ms |
596 KB |
Output is correct |
8 |
Correct |
4 ms |
596 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
724 KB |
Output is correct |
2 |
Correct |
40 ms |
724 KB |
Output is correct |
3 |
Correct |
96 ms |
724 KB |
Output is correct |
4 |
Correct |
83 ms |
724 KB |
Output is correct |
5 |
Correct |
160 ms |
740 KB |
Output is correct |
6 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 6 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
852 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
892 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |