이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, int>;
const int N = 2e3+10;
const int INF = INT_MAX;
int mxx = 0, mxy = 0;
unordered_map<ll, int> idx;
int dist[N];
bool vis[N];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
inline ll gethash(int x, int y) {
return x*1ll*(mxy+10)+y;
}
int DistanceSum(int n, int *X, int *Y)
{
int mnx = INF, mny = INF;
for (int i = 0; i < n; ++i) {
mnx = min(mnx, X[i]);
mny = min(mny, Y[i]);
}
for (int i = 0; i < n; ++i) {
X[i] -= mnx;
Y[i] -= mny;
mxx = max(mxx, X[i]);
mxy = max(mxy, Y[i]);
}
for (int i = 0; i < n; ++i) {
idx.emplace(gethash(X[i], Y[i]), i);
}
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j)
vis[j] = dist[j] = 0;
queue<int> nxt;
nxt.push(i);
while (!nxt.empty()) {
int j = nxt.front();
int x = X[j];
int y = Y[j];
nxt.pop();
if (j > i) {
ans += dist[j];
ans %= (int)1e9;
}
for (int k = 0; k < 4; ++k) {
int nx = x+dx[k];
int ny = y+dy[k];
if (!idx.count(gethash(nx, ny)))
continue;
int nj = idx[gethash(nx, ny)];
if (!vis[nj]) {
vis[nj] = true;
dist[nj] = dist[j]+1;
nxt.push(nj);
}
}
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:40:30: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
vis[j] = dist[j] = 0;
~~~~~~~~^~~
# | 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... |