Submission #120475

# Submission time Handle Problem Language Result Execution time Memory
120475 2019-06-24T15:53:39 Z nvmdava Parachute rings (IOI12_rings) C++17
100 / 100
2658 ms 196828 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

vector<pair<int, int> > con;
vector<int> adj[1000005];
set<int> pos, t;
int N;
int p[1000005][5];
void Init(int N_) {
  N = N_;
  for(int i = 0; i < N; i++)
   for(int j = 0; j < 5; j++)
      p[i][j] = i;
   for(int i = 0; i < N; i++)
      pos.insert(i);
}
int put = 0;
int v[10];

int find(int v, int i){
   if(v == p[v][i]) return v;
   return p[v][i] = find(p[v][i], i);
}

bool merge(int v, int u, int i){
   if(i){
      if(v == ::v[i]) return 0;
      if(u == ::v[i]) return 0;
   }
   v = find(v, i);
   u = find(u, i);
   if(v == u) return 1;
   p[v][i] = u;
   return 0;
}

bool dfs(int A, int B){
   t.insert(A);
   for(int x : adj[A]){
      if(x == B) continue;
      if(t.count(x)) return 1;
      if(dfs(x, A)) return 1;
   }
   t.erase(A);
   return 0;
}

void Link(int A, int B){
   if(pos.empty()) return;
   adj[A].push_back(B);
   adj[B].push_back(A);
   if(adj[A].size() == 4){
      t.clear();
      if(pos.count(A))
         t.insert(A);
      swap(t, pos);
   } else if(adj[A].size() == 3){
      t.clear();
      if(pos.count(A))
         t.insert(A);
      for(int x : adj[A])
         if(pos.count(x))
            t.insert(x);
      swap(t, pos);
   }
   if(adj[B].size() == 4){
      t.clear();
      if(pos.count(B))
         t.insert(B);
      swap(t, pos);
   } else if(adj[B].size() == 3){
      t.clear();
      if(pos.count(B))
         t.insert(B);
      for(int x : adj[B])
         if(pos.count(x))
            t.insert(x);
      swap(t, pos);
   }
   if(put == 0 && pos.size() <= 4){
      for(int x : pos){
         v[++put] = x;
      }
      for(auto& x : con){
         for(int j = 1; j <= put; j++){
            if(v[j] == -1 || merge(x.ff, x.ss, j)) v[j] = -1;
         }
      }
   }
   con.push_back({A, B});
   if(put){
      t.clear();
      for(int j = 1; j <= put; j++){
         if(v[j] == -1 || merge(A, B, j)) v[j] = -1;
         if(pos.count(v[j])) t.insert(v[j]);
      }
      swap(t, pos);
      return;
   }
   if(pos.empty()) return;
   if(put || merge(A, B, 0) == 0) return;
   t.clear();
   dfs(A, B);
   set<int> lol;
   for(int x : t)
      if(pos.count(x))
         lol.insert(x);
   swap(lol, pos);
}

int CountCritical() {
  return pos.size();
}

Compilation message

rings.cpp: In function 'void Init(int)':
rings.cpp:13:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   for(int i = 0; i < N; i++)
   ^~~
rings.cpp:16:4: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
    for(int i = 0; i < N; i++)
    ^~~
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23808 KB Output is correct
2 Correct 26 ms 24184 KB Output is correct
3 Correct 26 ms 24320 KB Output is correct
4 Correct 24 ms 23936 KB Output is correct
5 Correct 25 ms 24448 KB Output is correct
6 Correct 28 ms 24832 KB Output is correct
7 Correct 23 ms 24312 KB Output is correct
8 Correct 25 ms 24320 KB Output is correct
9 Correct 25 ms 24320 KB Output is correct
10 Correct 25 ms 24368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 626 ms 79308 KB Output is correct
2 Correct 1647 ms 95672 KB Output is correct
3 Correct 586 ms 91428 KB Output is correct
4 Correct 1689 ms 130180 KB Output is correct
5 Correct 1729 ms 132768 KB Output is correct
6 Correct 2658 ms 196828 KB Output is correct
7 Correct 871 ms 91564 KB Output is correct
8 Correct 1809 ms 120432 KB Output is correct
9 Correct 1984 ms 129320 KB Output is correct
10 Correct 1213 ms 128276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23808 KB Output is correct
2 Correct 26 ms 24184 KB Output is correct
3 Correct 26 ms 24320 KB Output is correct
4 Correct 24 ms 23936 KB Output is correct
5 Correct 25 ms 24448 KB Output is correct
6 Correct 28 ms 24832 KB Output is correct
7 Correct 23 ms 24312 KB Output is correct
8 Correct 25 ms 24320 KB Output is correct
9 Correct 25 ms 24320 KB Output is correct
10 Correct 25 ms 24368 KB Output is correct
11 Correct 26 ms 24444 KB Output is correct
12 Correct 28 ms 25088 KB Output is correct
13 Correct 30 ms 24844 KB Output is correct
14 Correct 27 ms 24568 KB Output is correct
15 Correct 30 ms 25196 KB Output is correct
16 Correct 29 ms 25088 KB Output is correct
17 Correct 28 ms 24568 KB Output is correct
18 Correct 30 ms 25336 KB Output is correct
19 Correct 29 ms 25084 KB Output is correct
20 Correct 33 ms 24924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23808 KB Output is correct
2 Correct 26 ms 24184 KB Output is correct
3 Correct 26 ms 24320 KB Output is correct
4 Correct 24 ms 23936 KB Output is correct
5 Correct 25 ms 24448 KB Output is correct
6 Correct 28 ms 24832 KB Output is correct
7 Correct 23 ms 24312 KB Output is correct
8 Correct 25 ms 24320 KB Output is correct
9 Correct 25 ms 24320 KB Output is correct
10 Correct 25 ms 24368 KB Output is correct
11 Correct 26 ms 24444 KB Output is correct
12 Correct 28 ms 25088 KB Output is correct
13 Correct 30 ms 24844 KB Output is correct
14 Correct 27 ms 24568 KB Output is correct
15 Correct 30 ms 25196 KB Output is correct
16 Correct 29 ms 25088 KB Output is correct
17 Correct 28 ms 24568 KB Output is correct
18 Correct 30 ms 25336 KB Output is correct
19 Correct 29 ms 25084 KB Output is correct
20 Correct 33 ms 24924 KB Output is correct
21 Correct 56 ms 28852 KB Output is correct
22 Correct 77 ms 31684 KB Output is correct
23 Correct 91 ms 33776 KB Output is correct
24 Correct 102 ms 30840 KB Output is correct
25 Correct 62 ms 30792 KB Output is correct
26 Correct 107 ms 31224 KB Output is correct
27 Correct 105 ms 33752 KB Output is correct
28 Correct 65 ms 30840 KB Output is correct
29 Correct 71 ms 31396 KB Output is correct
30 Correct 145 ms 37076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23808 KB Output is correct
2 Correct 26 ms 24184 KB Output is correct
3 Correct 26 ms 24320 KB Output is correct
4 Correct 24 ms 23936 KB Output is correct
5 Correct 25 ms 24448 KB Output is correct
6 Correct 28 ms 24832 KB Output is correct
7 Correct 23 ms 24312 KB Output is correct
8 Correct 25 ms 24320 KB Output is correct
9 Correct 25 ms 24320 KB Output is correct
10 Correct 25 ms 24368 KB Output is correct
11 Correct 626 ms 79308 KB Output is correct
12 Correct 1647 ms 95672 KB Output is correct
13 Correct 586 ms 91428 KB Output is correct
14 Correct 1689 ms 130180 KB Output is correct
15 Correct 1729 ms 132768 KB Output is correct
16 Correct 2658 ms 196828 KB Output is correct
17 Correct 871 ms 91564 KB Output is correct
18 Correct 1809 ms 120432 KB Output is correct
19 Correct 1984 ms 129320 KB Output is correct
20 Correct 1213 ms 128276 KB Output is correct
21 Correct 26 ms 24444 KB Output is correct
22 Correct 28 ms 25088 KB Output is correct
23 Correct 30 ms 24844 KB Output is correct
24 Correct 27 ms 24568 KB Output is correct
25 Correct 30 ms 25196 KB Output is correct
26 Correct 29 ms 25088 KB Output is correct
27 Correct 28 ms 24568 KB Output is correct
28 Correct 30 ms 25336 KB Output is correct
29 Correct 29 ms 25084 KB Output is correct
30 Correct 33 ms 24924 KB Output is correct
31 Correct 56 ms 28852 KB Output is correct
32 Correct 77 ms 31684 KB Output is correct
33 Correct 91 ms 33776 KB Output is correct
34 Correct 102 ms 30840 KB Output is correct
35 Correct 62 ms 30792 KB Output is correct
36 Correct 107 ms 31224 KB Output is correct
37 Correct 105 ms 33752 KB Output is correct
38 Correct 65 ms 30840 KB Output is correct
39 Correct 71 ms 31396 KB Output is correct
40 Correct 145 ms 37076 KB Output is correct
41 Correct 390 ms 70860 KB Output is correct
42 Correct 888 ms 102436 KB Output is correct
43 Correct 550 ms 90564 KB Output is correct
44 Correct 572 ms 97896 KB Output is correct
45 Correct 745 ms 101036 KB Output is correct
46 Correct 1031 ms 121380 KB Output is correct
47 Correct 2093 ms 165116 KB Output is correct
48 Correct 573 ms 98932 KB Output is correct
49 Correct 1111 ms 131912 KB Output is correct
50 Correct 1177 ms 130556 KB Output is correct
51 Correct 566 ms 81632 KB Output is correct
52 Correct 491 ms 83888 KB Output is correct
53 Correct 565 ms 97904 KB Output is correct
54 Correct 1754 ms 108292 KB Output is correct
55 Correct 1770 ms 95252 KB Output is correct