이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
vector<int> adj[MAXN];
void dfs(int node, vector<int> &vis)
{
vis[node] = 1;
for(auto a:adj[node])
if(!vis[a])
dfs(a, vis);
}
int construct_roads(vector<int> x, vector<int> y)
{
int n = x.size();
vector<vector<int>> ft(10, vector<int>(MAXN, -1));
for (int i = 0; i < n; i++)
ft[x[i]][y[i]] = i;
vector<pair<int, int>> dir{{2, 0}, {-2, 0}, {0, 2}, {0, -2}};
vector<int> u, v, a, b;
for(int i=0;i<n;i++)
{
for(auto d:dir)
{
int cx = x[i] + d.first, cy = y[i] + d.second;
if(ft[cx][cy] == -1)
continue;
adj[i].push_back(ft[cx][cy]);
if(ft[cx][cy] > i)
{
u.push_back(i);
v.push_back(ft[cx][cy]);
if(d.second == 0)
{
a.push_back(x[i] + cx >> 1);
b.push_back(cy - 1);
}
else
{
if(x[i] == 2)
{
a.push_back(x[i] - 1);
b.push_back(y[i] + cy >> 1);
}
else
{
a.push_back(x[i] + 1);
b.push_back(y[i] + cy >> 1);
}
}
}
}
}
vector<int> vis(n, 0);
dfs(0, vis);
for(int i=0;i<n;i++)
if(!vis[i])
return 0;
build(u, v, a, b);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:35:38: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | a.push_back(x[i] + cx >> 1);
parks.cpp:43:42: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
43 | b.push_back(y[i] + cy >> 1);
parks.cpp:48:42: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
48 | b.push_back(y[i] + cy >> 1);
# | 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... |