Submission #118708

# Submission time Handle Problem Language Result Execution time Memory
118708 2019-06-19T13:08:27 Z nvmdava Flood (IOI07_flood) C++17
42 / 100
186 ms 7008 KB
#include <bits/stdc++.h>
#define ss second
#define ff first
using namespace std;

vector<int> pr[4] = {{3, 0, 1, 2}, {0, 1, 2, 3}, {1, 2, 3, 0}, {2, 3, 0, 1}};

int x[100005], y[100005];
pair<int, int> wall[200005];
vector<int> dot;
int to[4][100005];
set<int> in;
set<int> ans;
int last;

void remove(int id){
   int v = wall[id].ff, u = wall[id].ss;
   for(int i = 0; i < 4; i++){
      if(to[i][v] == id) to[i][v] = -1;
      if(to[i][u] == id) to[i][u] = -1;
   }
}

int change(int& v){
   for(int x : pr[last]){
      if(to[x][v] != -1){
         int e = to[x][v];
         if(in.count(e))
            ans.insert(e);
         else in.insert(e);
         v = wall[e].ff + wall[e].ss - v;
         last = x;
         break;
      }
   }
   return v;
}

int main(){
   memset(to, -1, sizeof to);
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   int n;
   cin>>n;
   for(int i = 0; i < n; i++){
      cin>>x[i]>>y[i];
      dot.push_back(i);
   }
   sort(dot.begin(), dot.end(), [](const int& lhs,const int& rhs){
        if(x[lhs] != x[rhs]) return x[lhs] < x[rhs];
        return y[lhs] < y[rhs];
   });

   int w;
   cin>>w;
   for(int i = 0; i < w; i++){
      int v, u;
      cin>>v>>u;
      v--;u--;
      wall[i].ff = v;
      wall[i].ss = u;
      if(x[v] == x[u]){
         if(y[v] < y[u])
            swap(v, u);
         to[0][u] = i;
         to[2][v] = i;
      } else {
         if(x[v] < x[u])
            swap(v, u);
         to[1][u] = i;
         to[3][v] = i;
      }
   }
   for(int a : dot){
      if(to[0][a] + to[1][a] + to[2][a] + to[3][a] == -4) continue;
      last = 1;
      in.clear();
      int v = a;
      while(change(v) != a);
      for(int x : in) remove(x);
   }
   cout<<ans.size()<<'\n';
   for(int x : ans)
      cout<<x + 1<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1920 KB Output is correct
2 Correct 3 ms 1920 KB Output is correct
3 Correct 4 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1920 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1920 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1920 KB Output is correct
2 Correct 4 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 3004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 5596 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 85 ms 3860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 170 ms 6904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 186 ms 7008 KB Output isn't correct
2 Halted 0 ms 0 KB -