# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
211946 | tatyam | Flood (IOI07_flood) | C++17 | 2088 ms | 12652 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using tuplis = array<int, 3>;
#define rep(b) for(int i = 0; i < b; i++)
#define each(i,a) for(auto&& i : a)
#define all(a) begin(a), end(a)
struct wall{
int to = -1, index;
wall(){}
wall(int to, int index): to(to), index(index){}
bool exist() const { return to + 1; }
};
int main(){
int n;
scanf("%d", &n);
vector<pii> p(n);
each(i, p) scanf("%d%d", &i.first, &i.second);
map<pii, int> min_p;
rep(n) min_p[{p[i].first, p[i].second}] = i;
vector<array<wall, 4>> g(n);
auto submerge = [&](int i) -> void {
if(!any_of(all(g[i]), [](const wall& w){ return w.exist(); })) min_p.erase({p[i].first, p[i].second});
};
int w;
scanf("%d", &w);
rep(w){
int a, b;
scanf("%d%d", &a, &b);
a--; b--;
int d = 0;
if(p[a].first < p[b].first) d = 0;
else if(p[a].first > p[b].first) d = 2;
else if(p[a].second < p[b].second) d = 1;
else d = 3;
g[a][d] = {b, i};
g[b][d ^ 2] = {a, i};
}
vector<bool> ans(w, 1);
while(min_p.size()){
int start = min_p.begin()->second, at = start, d = 0;
vector<pii> visit;
if(!g[at][d].exist()) d = 1;
do{
if(!g[at][d].exist()){
d++;
d &= 3;
continue;
}
visit.emplace_back(at, d);
ans[g[at][d].index] = !ans[g[at][d].index];
at = g[at][d].to;
d--;
d &= 3;
}while(at != start);
each(i, visit){
int at, d;
tie(at, d) = i;
if(!g[at][d].exist()) continue;
int at2 = g[at][d].to, d2 = d ^ 2;
g[at][d].to = -1;
g[at2][d2].to = -1;
submerge(at);
submerge(at2);
}
}
printf("%d\n", accumulate(ans.begin(), ans.end(), 0));
rep(w) if(ans[i]) printf("%d\n", i + 1);
}
Compilation message (stderr)
# | 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... |