답안 #118028

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118028 2019-06-17T17:45:50 Z IOrtroiii Collapse (JOI18_collapse) C++14
5 / 100
15000 ms 10360 KB
#include <bits/stdc++.h>
#include "collapse.h"
using namespace std;

vector<int> par;
vector<int> par2;
vector<int> last;
int tt;

int find(int u) {
   if (par[u] == u) {
      return u;
   } else {
      return par[u] = find(par[u]);
   }
}

bool merge(int u, int v) {
   u = find(u);
   v = find(v);
   if (u == v) {
      return false;
   } else {
      par[v] = u;
      return true;
   }
}

int find2(int u) {
   if (last[u] != tt) {
      last[u] = tt;
      par2[u] = par[u];
   }
   if (par2[u] == u) {
      return u;
   } else {
      return par2[u] = find2(par2[u]);
   }
}

bool merge2(int u, int v) {
   u = find2(u);
   v = find2(v);
   if (u == v) {
      return false;
   } else {
      par2[v] = u;
      return true;
   }
}

vector<int> simulateCollapse(int n, vector<int> type, vector<int> from, vector<int> to, vector<int> time, vector<int> pos) {
   int m = type.size();
   int q = time.size();
   par.resize(n);
   par2.resize(n);
   last.assign(n, 0);
   for (int i = 0; i < m; ++i) {
      if (from[i] > to[i]) {
         swap(from[i], to[i]);
      }
   }
   vector<int> go(m);
   {
      map<pair<int, int>, int> st;
      for (int i = 0; i < m; ++i) {
         pair<int, int> e = make_pair(from[i], to[i]);
         if (type[i] == 0) {
            st[e] = i;
         } else {
            assert(st.count(e));
            go[st[e]] = i;
            st.erase(e);
         }
      }
      for (auto p : st) {
         go[p.second] = m;
      }
   }
   vector<int> ans(q);
   for (int i = 0; i < q; ++i) {
      int ncomp = n;
      for (int j = 0; j < n; ++j) {
         par[j] = j;
      }
      for (int j = 0; j < m; ++j) {
         if (type[j] == 0 && j <= time[i] && time[i] < go[j]) {
            if (to[j] <= pos[i] || from[j] > pos[i]) {
               ncomp -= merge(from[j], to[j]);
            }
         }
      }
      ans[i] = ncomp;
   }
   return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 512 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 147 ms 768 KB Output is correct
6 Correct 173 ms 968 KB Output is correct
7 Correct 14 ms 512 KB Output is correct
8 Correct 15 ms 512 KB Output is correct
9 Correct 156 ms 760 KB Output is correct
10 Correct 201 ms 888 KB Output is correct
11 Correct 231 ms 1144 KB Output is correct
12 Correct 313 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 2296 KB Output is correct
2 Correct 26 ms 2304 KB Output is correct
3 Execution timed out 15055 ms 5024 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 2304 KB Output is correct
2 Correct 26 ms 2304 KB Output is correct
3 Correct 35 ms 2832 KB Output is correct
4 Correct 42 ms 2788 KB Output is correct
5 Correct 499 ms 3192 KB Output is correct
6 Correct 3444 ms 3676 KB Output is correct
7 Execution timed out 15053 ms 10360 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 512 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 147 ms 768 KB Output is correct
6 Correct 173 ms 968 KB Output is correct
7 Correct 14 ms 512 KB Output is correct
8 Correct 15 ms 512 KB Output is correct
9 Correct 156 ms 760 KB Output is correct
10 Correct 201 ms 888 KB Output is correct
11 Correct 231 ms 1144 KB Output is correct
12 Correct 313 ms 1024 KB Output is correct
13 Correct 22 ms 2296 KB Output is correct
14 Correct 26 ms 2304 KB Output is correct
15 Execution timed out 15055 ms 5024 KB Time limit exceeded
16 Halted 0 ms 0 KB -