이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3e2;
int p[N];
int find(int x){
return (x == p[x] ? x : p[x] = find(p[x]));
}
bool unite(int x, int y){
x = find(x);
y = find(y);
if (x == y) return false;
if (rand() & 1) swap(x, y);
p[x] = y;
return true;
}
int construct_roads(vector<int> x, vector<int> y) {
int n = x.size();
if (n == 1) {
build({}, {}, {}, {});
return 1;
}
iota(p, p + n, 0);
map<pair<int, int>, int> id;
for (int i = 0; i < n; i++){
id[{x[i], y[i]}] = i;
}
vector<int> U, V, A, B;
vector<int> dx = {2, 0, -2, 0};
vector<int> dy = {0, 2, 0, -2};
for (int i = 0; i < n; i++){
for (int it = 0; it < 4; it++){
int X = x[i] + dx[it], Y = y[i] + dy[it];
if (id.find({X, Y}) != id.end()){
int j = id[{X, Y}];
if (!unite(i, j)) continue;
U.push_back(i);
V.push_back(j);
}
}
}
if (U.size() != n - 1) return 0;
for (int it = 0; it < n - 1; it++){
int i = U[it], j = V[it];
if (y[i] == y[j]){
A.push_back((x[i] + x[j]) / 2);
B.push_back(y[i] + 1);
} else {
A.push_back((x[i] == 2 ? 1 : 5));
B.push_back((y[i] + y[j]) / 2);
}
}
build(U, V, A, B);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:54:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
54 | if (U.size() != n - 1) return 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |