# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
54360 | khsoo01 | Flood (IOI07_flood) | C++11 | 141 ms | 7564 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>
#define X first
#define Y second
using namespace std;
typedef pair<int,int> pii;
const int N = 200005;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
int n, m, x[N], y[N], a[N], b[N], nxt[N][4];
bool col[N], vis[N][2];
vector<int> wait, ans;
priority_queue<pair<pii,int> > pq;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) {
scanf("%d%d",&x[i],&y[i]);
}
scanf("%d",&m);
for(int i=1;i<=m;i++) {
int A, B;
scanf("%d%d",&A,&B);
if(x[A] > x[B] || y[A] > y[B]) swap(A, B);
a[i] = A;
b[i] = B;
if(y[A] == y[B]) {
nxt[A][0] = i;
nxt[B][2] = i;
}
else {
nxt[A][3] = i;
nxt[B][1] = i;
}
pq.push({{x[B], -y[B]}, i});
}
while(!pq.empty()) {
int T = pq.top().Y;
pq.pop();
if(col[T]) continue;
int V = a[T], P = (x[a[T]] == x[b[T]] ? 1 : 2);
for(;;) {
int D, Z;
for(int i=0;i<4;i++) {
D = (P + 3 + i) % 4;
Z = nxt[V][D];
if(Z && !col[Z]) break;
}
if(vis[Z][D<2]) break;
vis[Z][D<2] = true;
wait.push_back(Z);
V = a[Z] + b[Z] - V;
P = D;
}
for(auto &T : wait) {
col[T] = true;
}
wait.clear();
}
for(int i=1;i<=m;i++) {
if(vis[i][0] && vis[i][1]) ans.push_back(i);
}
printf("%d\n",(int)ans.size());
sort(ans.begin(), ans.end());
for(auto &T : ans) {
printf("%d\n",T);
}
}
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... |