# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
211954 |
2020-03-21T20:04:31 Z |
tatyam |
Flood (IOI07_flood) |
C++17 |
|
115 ms |
6896 KB |
#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(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<pii> p(n);
each(i, p) cin >> i.first >> i.second;
vector<array<wall, 4>> g(n);
int w;
cin >> w;
rep(w){
int a, b;
cin >> 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);
vector<int> sorted(n);
iota(all(sorted), 0);
sort(all(sorted), [&](int a, int b){ return p[a] < p[b]; });
int i = 0;
while(true){
while(i < n && all_of(all(g[sorted[i]]), [](const wall& w){ return !w.exist(); })) i++;
if(i == n) break;
int start = sorted[i], 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;
}
}
cout << accumulate(ans.begin(), ans.end(), 0) << '\n';
rep(w) if(ans[i]) cout << i + 1 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
4600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
4216 KB |
Output is correct |
2 |
Correct |
91 ms |
5156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
5112 KB |
Output is correct |
2 |
Correct |
115 ms |
5072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
5112 KB |
Output is correct |
2 |
Correct |
79 ms |
6896 KB |
Output is correct |