이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//#undef LOCALKL
#define IO \
ios_base::sync_with_stdio(0);(cin).tie(0);(cout).tie(0)
#define y1 y1_
#define prev prev_
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#ifdef LOCALKL
#define cerr cerr<<"\33[1;32m"
#define cout cout<<"\33[0m"
#else
#define endl '\n'
#define cerr if(1){}else cerr
#endif
#define OK cout<<"OK\n"<<endl;
#define setpre(k) fixed<<setprecision(k)
#define mmset(k,y) memset(k,y,sizeof(k))
#define sz(x) ((int)(x).size())
using pii = pair<int,int>;
using pll = pair<long long,long long>;
using ull = unsigned long long;
using intt = long long;
using ll = long long;
using ld = long double;
const ll m9 = 998244353;
const ll m7 = 1000000007;
const ll m18 = 1000000000000000000;
const ll i127 = 2139062143;
const ll l127 = 9187201950435737471;
struct visited
{
int x=0,y=0;
int d=0;
};
ll ans = 0;
int xx[4] = {0, 0,1,-1};
int yy[4] = {1,-1,0, 0};
bool g[2003][2003];
short int c[2003][2003];
int minx=INT_MAX, miny=INT_MAX;
queue<visited>q;
int DistanceSum(int n, int *X, int *Y)
{
mmset(c,-1);
for(int i=0;i<n;i++)
{
minx = min(minx, X[i]);
miny = min(miny, Y[i]);
}
minx--; miny--;
for(int i=0;i<n;i++) g[X[i] - minx][Y[i] - miny]=1;
for(int i=0;i<n;i++)
{
q.push({X[i] - minx, Y[i] - miny, 0});
c[X[i] - minx][Y[i] - miny] = i;
while(!q.empty())
{
auto v = q.front();
// cerr<<v.x<<';'<<v.y<<' '<<v.d<<endl;
q.pop();
ans += v.d;
for(int j=0;j<4;j++)
if(g[v.x+xx[j]][v.y+yy[j]] and c[v.x+xx[j]][v.y+yy[j]]!=i)
{
c[v.x+xx[j]][v.y+yy[j]]=i;
q.push({v.x+xx[j], v.y+yy[j], v.d+1});
}
}
// cerr<<X[i] - minx<<' '<<Y[i] - miny<<' '<<ans<<endl;
}
return ans>>1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |