# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1029765 | aufan | 분수 공원 (IOI21_parks) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
const auto fx[] = {1, 1, -1, -1};
const auto fy[] = {1, -1, 1, -1};
const auto dx[] = {2, 0, -2, 0};
const auto dy[] = {0, 2, 0, -2};
int construct_roads(vector<int> x, vector<int> y) {
int n = (int)x.size();
map<pair<int, int>, int> id;
set<pair<int, int>> pos;
for (int i = 0; i < n; i++) {
id[{x[i], y[i]}] = i;
for (int k = 0; k < 4; k++) {
int nx = x[i] + fx[k];
int ny = y[i] + fy[k];
pos.insert({nx, ny});
}
}
vector<int> vis(n);
function<void(int)> dfs = [&](int z) {
vis[z] = 1;
for (int k = 0; k < 4; k++) {
int nx = x[z] + dx[k];
int ny = y[z] + dy[k];
if (id.count({nx, ny})) {
int p = id[{nx, ny}];
if (!vis[p]) {
dfs(p);
}
}
}
};
dfs(0);
if (count(vis.begin(), vis.end(), 1) != n) {
return 0;
}
vector<int> u, v, a, b;
for (auto [cx, cy] : pos) {
if ((cx + cy) % 4 == 0) {
if (id.count({cx - 1, cy - 1}) && id.count({cx - 1, cy + 1})) {
u.push_back(id[{cx - 1, cy - 1}]);
v.push_back(id[{cx - 1, cy + 1}]);
a.push_back(cx);
b.push_back(cy);
} else if (id.count({cx + 1, cy - 1}) && id.count({cx + 1, cy + 1})) {
u.push_back(id[{cx + 1, cy - 1}]);
v.push_back(id[{cx + 1, cy + 1}]);
a.push_back(cx);
b.push_back(cy);
}
} else if ((cx + cy) % 4 == 2) {
if (id.count({cx - 1, cy - 1}) && id.count({cx + 1, cy - 1})) {
u.push_back(id[{cx - 1, cy - 1}]);
v.push_back(id[{cx + 1, cy - 1}]);
a.push_back(cx);
b.push_back(cy);
} else if (id.count({cx - 1, cy + 1}) && id.count({cx + 1, cy + 1})) {
u.push_back(id[{cx - 1, cy + 1}]);
v.push_back(id[{cx + 1, cy + 1}]);
a.push_back(cx);
b.push_back(cy);
}
}
}
build(u, v, a, b);
return 1;
}