이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define lint long long
#define endl '\n'
#define pii pair<int, int>
#define pll pair<lint, lint>
#define For(i,n) for (int i = 0; i < n; i++)
#define FOR For(i, n)
using namespace std;
const int N = 1e5;
map<pii, int> vis[N];
map<pii, int> visc;
map<pii, lint> dist;
void validpush(queue<pair<int, pair<lint, pii>>>& q, int tourist, int depth, int x, int y) {
if (x >= 1e9 || y >= 1e9) return;
if (x < 0 || y < 0) return;
if ((x & y)) return;
if (vis[tourist][{x,y}]) return;
q.push({tourist, {depth, {x,y}}});
}
int main() {
int n; cin >> n;
vector<pii> ts(n);
FOR {
int x,y; cin >> x >> y;
ts[i] = {x,y};
}
queue<pair<int, pair<lint, pair<int, int>>>> q; lint fdepth = -1; lint mn = 2e18;
FOR q.push({ i, { 0ll, { ts[i].first, ts[i].second } } });
while (!q.empty()) {
int tourist = q.front().first;
lint depth = q.front().second.first;
int x = q.front().second.second.first;
int y = q.front().second.second.second;
q.pop();
if (vis[tourist][{x,y}]) continue;
vis[tourist][{x,y}] = true;
visc[{x,y}]++;
//cerr << "depth tourist=" << tourist << " x,y=" << x << "," << y << " " << "depth=" << depth << endl;
dist[{x,y}] += depth;
if (visc[{x,y}] == n) {
cout << dist[{x,y}] << endl;
return 0;
fdepth = depth;
mn = min(mn, dist[{x,y}]);
//cerr << x << " " << y << endl;
continue;
}
validpush(q, tourist, depth+1, x, y+1);
validpush(q, tourist, depth+1, x-1, y);
validpush(q, tourist, depth+1, x, y-1);
validpush(q, tourist, depth+1, x+1, y);
}
cout << mn << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
cvenk.cpp: In function 'int main()':
cvenk.cpp:32:55: warning: variable 'fdepth' set but not used [-Wunused-but-set-variable]
32 | queue<pair<int, pair<lint, pair<int, int>>>> q; lint fdepth = -1; lint mn = 2e18;
| ^~~~~~
# | 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... |