이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int DIM = 1e5 + 5;
const int NWALL = 2e5 + 5;
///Nord, Vest, Sud, Est
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int n, w;
int x[DIM], y[DIM];
pair <int, int> wh[DIM][4];
int cnt[NWALL];
bool viz[NWALL];
struct elem {
int x, y, id;
bool operator < (const elem &aux) const{
if (x != aux.x) return x < aux.x;
return y > aux.y;
}
};
int opus(int dir) {
if (dir == 0 || dir == 2) dir = 2 - dir;
else dir = 4 - dir;
return dir;
}
void dfs(int nod, int dir, int root) {
if (dir == 4) dir = 0;
for (int d = dir + 1; d <= dir + 4 ; ++d) {
int real = d;
if (real >= 4) real -= 4;
if (wh[nod][real].first == 0 || viz[wh[nod][real].second]) continue ;
++cnt[wh[nod][real].second];
int aux = wh[nod][real].first;
wh[nod][real].first = 0;
if (aux != root)
dfs(aux, opus(real), root);
viz[wh[nod][real].second] = 1;
break ;
}
}
int main() {
#ifdef HOME
freopen("flood.in", "r", stdin);
freopen("flood.out", "w", stdout);
#endif // HOME
scanf("%d", &n);
vector <elem> point;
for (int i = 1; i <= n ; ++i) {
scanf("%d%d", &x[i], &y[i]);
point.push_back({x[i], y[i], i});
}
scanf("%d", &w);
int a, b;
for (int i = 1; i <= w ; ++i) {
scanf("%d%d", &a, &b);
if (x[a] == x[b]) {
if (y[a] > y[b]) swap(a, b);
wh[a][0] = {b, i};
wh[b][2] = {a, i};
} else {
if (x[a] > x[b]) swap(a, b);
wh[a][3] = {b, i};
wh[b][1] = {a, i};
}
}
sort (point.begin(), point.end());
for (auto it : point) {
for (int dir = 1; dir <= 3 ; ++dir)
if (wh[it.id][dir].first) dfs(it.id, 1, it.id);
if (wh[it.id][0].first) dfs(it.id, 1, it.id);
}
vector <int> sol;
for (int i = 1; i <= w ; ++i)
if (cnt[i] == 2) sol.push_back(i);
printf("%d\n", sol.size());
for (auto it : sol) printf("%d\n", it);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
flood.cpp: In function 'int main()':
flood.cpp:99:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
99 | printf("%d\n", sol.size());
| ~^ ~~~~~~~~~~
| | |
| int std::vector<int>::size_type {aka long unsigned int}
| %ld
flood.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
60 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
flood.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
64 | scanf("%d%d", &x[i], &y[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
flood.cpp:68:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
68 | scanf("%d", &w);
| ~~~~~^~~~~~~~~~
flood.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
72 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
# | 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |