이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
struct edges{
int x,y,x1,y1;
};
int construct_roads(std::vector<int> x, std::vector<int> y) {
map<pair<int,int>,bool>mp,got;
map<pair<int,int>,int>index,need;
int n = (int)x.size();
for (int i = 0;i<n;++i){
mp[{x[i],y[i]}] = true;
got[{x[i],y[i]}] = false;
index[{x[i],y[i]}] = i;
}
auto comp = [&](int a,int b,int c,int d){
if (a<c){
return (edges){a,b,c,d};
}
else if (c < a){
return (edges){c,d,a,b};
}
else if ( b < d){
return (edges){a,b,c,d};
}
return (edges){c,d,a,b};
};
vector<edges>ans;
vector<int>dx = {2,0,-2,0};
vector<int>dy = {0,2,0,-2};
function<void(int,int)> dfs = [&](int u,int v){
got[{u,v}] = true;
for (int i = 0;i<4;++i){
int xx = u + dx[i];
int yy = v + dy[i];
if (mp[{xx,yy}] && !got[{xx,yy}]){
ans.push_back(comp(u,v,xx,yy));
dfs(xx,yy);
}
}
};
bool ok = true;
dfs(x[0],y[0]);
for (int i = 0;i<n;++i){
if (!got[{x[i],y[i]}]){
ok=false;
break;
}
}
if (!ok){
return 0;
}
sort(ans.begin(),ans.end(),[&](auto xx,auto yy){
if (xx.x == yy.x)return xx.y < yy.y;
return xx.x<yy.x;
});
vector<int>u,v,a,b;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>q;
for (int i = 0;i<(int)ans.size();++i){
swap(ans[i].x,ans[i].x1);
swap(ans[i].y,ans[i].y1);
edges z = ans[i];
if (z.x == z.x1){
need[{z.x - 1,z.y - 1}]++;
need[{z.x + 1,z.y - 1}]++;
}
else{
need[{z.x - 1,z.y + 1}]++;
need[{z.x - 1,z.y - 1}]++;
}
}
for (int i = 0;i<(int)ans.size();++i){
edges z = ans[i];
int cost = 0;
if (z.x == z.x1){
cost = min(need[{z.x - 1,z.y - 1}],need[{z.x + 1,z.y - 1}]);
}
else{
cost = min(need[{z.x - 1,z.y - 1}],need[{z.x - 1,z.y + 1}]);
}
q.push({cost,i});
}
while(!q.empty()){
auto z = ans[q.top().second];
int temp = q.top().second;
q.pop();
if (z.x == z.x1){
if (need[{z.x - 1,z.y - 1}]<q.size()){
need[{z.x - 1,z.y - 1}] = INT_MAX;
need[{z.x + 1,z.y - 1}]--;
u.push_back(index[{z.x,z.y}]);
v.push_back(index[{z.x1,z.y1}]);
a.push_back(z.x - 1);
b.push_back(z.y - 1);
}
else if (need[{z.x + 1,z.y - 1}]<q.size()){
need[{z.x - 1,z.y - 1}]--;
need[{z.x + 1,z.y - 1}] = INT_MAX;
u.push_back(index[{z.x,z.y}]);
v.push_back(index[{z.x1,z.y1}]);
a.push_back(z.x + 1);
b.push_back(z.y - 1);
}
else q.push({min(need[{z.x - 1,z.y - 1}],need[{z.x + 1,z.y - 1}]),temp});
}
else{
if (need[{z.x - 1,z.y + 1}]<q.size()){
need[{z.x - 1,z.y + 1}] = INT_MAX;
need[{z.x - 1,z.y-1}]--;
u.push_back(index[{z.x,z.y}]);
v.push_back(index[{z.x1,z.y1}]);
a.push_back(z.x - 1);
b.push_back(z.y + 1);
}
else if (need[{z.x - 1,z.y - 1}]<q.size()){
need[{z.x - 1,z.y + 1}]--;
need[{z.x - 1,z.y - 1}] = INT_MAX;
u.push_back(index[{z.x,z.y}]);
v.push_back(index[{z.x1,z.y1}]);
a.push_back(z.x - 1);
b.push_back(z.y - 1);
}
else q.push({min(need[{z.x - 1,z.y + 1}],need[{z.x - 1,z.y - 1}]),temp});
}
}
build(u,v,a,b);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:88:31: warning: comparison of integer expressions of different signedness: 'std::map<std::pair<int, int>, int>::mapped_type' {aka 'int'} and 'std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, std::greater<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | if (need[{z.x - 1,z.y - 1}]<q.size()){
parks.cpp:96:36: warning: comparison of integer expressions of different signedness: 'std::map<std::pair<int, int>, int>::mapped_type' {aka 'int'} and 'std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, std::greater<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | else if (need[{z.x + 1,z.y - 1}]<q.size()){
parks.cpp:107:31: warning: comparison of integer expressions of different signedness: 'std::map<std::pair<int, int>, int>::mapped_type' {aka 'int'} and 'std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, std::greater<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | if (need[{z.x - 1,z.y + 1}]<q.size()){
parks.cpp:115:36: warning: comparison of integer expressions of different signedness: 'std::map<std::pair<int, int>, int>::mapped_type' {aka 'int'} and 'std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, std::greater<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | else if (need[{z.x - 1,z.y - 1}]<q.size()){
# | 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... |