Submission #1037137

# Submission time Handle Problem Language Result Execution time Memory
1037137 2024-07-28T08:38:38 Z 8pete8 Parachute rings (IOI12_rings) C++17
100 / 100
537 ms 122728 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
using namespace std;
const int mod=1e9+7,mxn=1e6+5,inf=1e9,minf=-1e9,lg=25;
int n;
vector<int>adj[mxn+10];
int found=-1;
struct dsu{
  int pa[mxn+10],ans=1,deg[mxn+10],sz[mxn+10];
  void init(){ans=1;for(int i=0;i<n;i++)pa[i]=i,deg[i]=0,sz[i]=1;}
  int find(int u){
    return (pa[u]==u)?u:pa[u]=find(pa[u]);
  }
  bool merg(int a,int b){
    int x=a,y=b;
    a=find(a),b=find(b);
    deg[x]++,deg[y]++;
    if(deg[x]==3||deg[y]==3)ans=0;
    if(a==b){
      ans=0;
      return 0;
    }
    pa[a]=b;
    sz[b]+=sz[a];
    return 1;
  }
}t[6];
vector<pii>event;
vector<int>have;
int havecycle=-1,why=0;
void Init(int N_){
  if(why)assert(0);
  found=-1;
  why++;
  havecycle=-1;
  n=N_;
  t[0].init();
}
void make(int node,int pos){
  t[pos].init();
  for(auto i:event)if(i.f!=node&&i.s!=node)t[pos].merg(i.f,i.s);
}
void Link(int a,int b){
  if(found!=-1){
    for(int i=0;i<have.size();i++)if(a!=have[i]&&b!=have[i])t[i+1].merg(a,b);
  }
  else{
    event.pb({a,b});
    if(t[0].merg(a,b)==0){
      if(havecycle==-1)havecycle=t[0].sz[t[0].find(b)];
      else havecycle=-2;
    }
    adj[a].pb(b);
    adj[b].pb(a);
    if(t[0].deg[a]==3)found=a;
    else if(t[0].deg[b]==3)found=b;
    if(found!=-1){
      have.pb(found);
      for(auto i:adj[found])have.pb(i);
      for(int i=0;i<have.size();i++)make(have[i],i+1);
    }
  } 
}
int CountCritical(){
  if(found!=-1){
    int sum=0;
    for(int i=0;i<have.size();i++)sum+=t[i+1].ans;
    return sum;
  }
  else if(havecycle==-2)return 0;
  else if(havecycle!=-1)return havecycle;
  return n;
}
 
/*
if we can find intersect from all these set:
1. in every cycle
2. have deg >=3
3. directly connected to deg 3
if there are no deg>3 then there can be atmost 4 candidates
because the node has to be directly connected to all deg 3 and every node deg<=3
if theres a node deg>3 we just have to check 1 node but the deg can be a lot
 
how to know if a node is in cycle?
*/

Compilation message

rings.cpp:32:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
   32 | #pragma GCC optimize ("03,unroll-lopps")
      |                                        ^
rings.cpp:40:13: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   40 |   void init(){ans=1;for(int i=0;i<n;i++)pa[i]=i,deg[i]=0,sz[i]=1;}
      |             ^
rings.cpp:41:17: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   41 |   int find(int u){
      |                 ^
rings.cpp:44:24: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   44 |   bool merg(int a,int b){
      |                        ^
rings.cpp:61:17: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   61 | void Init(int N_){
      |                 ^
rings.cpp:69:27: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   69 | void make(int node,int pos){
      |                           ^
rings.cpp:73:22: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   73 | void Link(int a,int b){
      |                      ^
rings.cpp: In function 'void Link(int, int)':
rings.cpp:75:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for(int i=0;i<have.size();i++)if(a!=have[i]&&b!=have[i])t[i+1].merg(a,b);
      |                 ~^~~~~~~~~~~~
rings.cpp:90:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |       for(int i=0;i<have.size();i++)make(have[i],i+1);
      |                   ~^~~~~~~~~~~~
rings.cpp: At global scope:
rings.cpp:94:19: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   94 | int CountCritical(){
      |                   ^
rings.cpp: In function 'int CountCritical()':
rings.cpp:97:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     for(int i=0;i<have.size();i++)sum+=t[i+1].ans;
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 38748 KB Output is correct
2 Correct 8 ms 55132 KB Output is correct
3 Correct 8 ms 55132 KB Output is correct
4 Correct 6 ms 38748 KB Output is correct
5 Correct 6 ms 38748 KB Output is correct
6 Correct 6 ms 39004 KB Output is correct
7 Correct 8 ms 55132 KB Output is correct
8 Correct 6 ms 38748 KB Output is correct
9 Correct 8 ms 55384 KB Output is correct
10 Correct 8 ms 55388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 65572 KB Output is correct
2 Correct 350 ms 104124 KB Output is correct
3 Correct 444 ms 86620 KB Output is correct
4 Correct 451 ms 86188 KB Output is correct
5 Correct 453 ms 86188 KB Output is correct
6 Correct 444 ms 84912 KB Output is correct
7 Correct 470 ms 86616 KB Output is correct
8 Correct 455 ms 117528 KB Output is correct
9 Correct 537 ms 122728 KB Output is correct
10 Correct 315 ms 85160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 38748 KB Output is correct
2 Correct 8 ms 55132 KB Output is correct
3 Correct 8 ms 55132 KB Output is correct
4 Correct 6 ms 38748 KB Output is correct
5 Correct 6 ms 38748 KB Output is correct
6 Correct 6 ms 39004 KB Output is correct
7 Correct 8 ms 55132 KB Output is correct
8 Correct 6 ms 38748 KB Output is correct
9 Correct 8 ms 55384 KB Output is correct
10 Correct 8 ms 55388 KB Output is correct
11 Correct 8 ms 55132 KB Output is correct
12 Correct 9 ms 57692 KB Output is correct
13 Correct 9 ms 57692 KB Output is correct
14 Correct 9 ms 57180 KB Output is correct
15 Correct 9 ms 57436 KB Output is correct
16 Correct 8 ms 39200 KB Output is correct
17 Correct 9 ms 57436 KB Output is correct
18 Correct 10 ms 57436 KB Output is correct
19 Correct 8 ms 39260 KB Output is correct
20 Correct 9 ms 57692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 38748 KB Output is correct
2 Correct 8 ms 55132 KB Output is correct
3 Correct 8 ms 55132 KB Output is correct
4 Correct 6 ms 38748 KB Output is correct
5 Correct 6 ms 38748 KB Output is correct
6 Correct 6 ms 39004 KB Output is correct
7 Correct 8 ms 55132 KB Output is correct
8 Correct 6 ms 38748 KB Output is correct
9 Correct 8 ms 55384 KB Output is correct
10 Correct 8 ms 55388 KB Output is correct
11 Correct 8 ms 55132 KB Output is correct
12 Correct 9 ms 57692 KB Output is correct
13 Correct 9 ms 57692 KB Output is correct
14 Correct 9 ms 57180 KB Output is correct
15 Correct 9 ms 57436 KB Output is correct
16 Correct 8 ms 39200 KB Output is correct
17 Correct 9 ms 57436 KB Output is correct
18 Correct 10 ms 57436 KB Output is correct
19 Correct 8 ms 39260 KB Output is correct
20 Correct 9 ms 57692 KB Output is correct
21 Correct 15 ms 42456 KB Output is correct
22 Correct 22 ms 43480 KB Output is correct
23 Correct 33 ms 46072 KB Output is correct
24 Correct 26 ms 62296 KB Output is correct
25 Correct 15 ms 63832 KB Output is correct
26 Correct 24 ms 64600 KB Output is correct
27 Correct 29 ms 45324 KB Output is correct
28 Correct 27 ms 62592 KB Output is correct
29 Correct 21 ms 64348 KB Output is correct
30 Correct 33 ms 48068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 38748 KB Output is correct
2 Correct 8 ms 55132 KB Output is correct
3 Correct 8 ms 55132 KB Output is correct
4 Correct 6 ms 38748 KB Output is correct
5 Correct 6 ms 38748 KB Output is correct
6 Correct 6 ms 39004 KB Output is correct
7 Correct 8 ms 55132 KB Output is correct
8 Correct 6 ms 38748 KB Output is correct
9 Correct 8 ms 55384 KB Output is correct
10 Correct 8 ms 55388 KB Output is correct
11 Correct 166 ms 65572 KB Output is correct
12 Correct 350 ms 104124 KB Output is correct
13 Correct 444 ms 86620 KB Output is correct
14 Correct 451 ms 86188 KB Output is correct
15 Correct 453 ms 86188 KB Output is correct
16 Correct 444 ms 84912 KB Output is correct
17 Correct 470 ms 86616 KB Output is correct
18 Correct 455 ms 117528 KB Output is correct
19 Correct 537 ms 122728 KB Output is correct
20 Correct 315 ms 85160 KB Output is correct
21 Correct 8 ms 55132 KB Output is correct
22 Correct 9 ms 57692 KB Output is correct
23 Correct 9 ms 57692 KB Output is correct
24 Correct 9 ms 57180 KB Output is correct
25 Correct 9 ms 57436 KB Output is correct
26 Correct 8 ms 39200 KB Output is correct
27 Correct 9 ms 57436 KB Output is correct
28 Correct 10 ms 57436 KB Output is correct
29 Correct 8 ms 39260 KB Output is correct
30 Correct 9 ms 57692 KB Output is correct
31 Correct 15 ms 42456 KB Output is correct
32 Correct 22 ms 43480 KB Output is correct
33 Correct 33 ms 46072 KB Output is correct
34 Correct 26 ms 62296 KB Output is correct
35 Correct 15 ms 63832 KB Output is correct
36 Correct 24 ms 64600 KB Output is correct
37 Correct 29 ms 45324 KB Output is correct
38 Correct 27 ms 62592 KB Output is correct
39 Correct 21 ms 64348 KB Output is correct
40 Correct 33 ms 48068 KB Output is correct
41 Correct 105 ms 58812 KB Output is correct
42 Correct 225 ms 108216 KB Output is correct
43 Correct 121 ms 91220 KB Output is correct
44 Correct 333 ms 98400 KB Output is correct
45 Correct 313 ms 97604 KB Output is correct
46 Correct 293 ms 92080 KB Output is correct
47 Correct 380 ms 93868 KB Output is correct
48 Correct 211 ms 94548 KB Output is correct
49 Correct 288 ms 88692 KB Output is correct
50 Correct 311 ms 88508 KB Output is correct
51 Correct 120 ms 91220 KB Output is correct
52 Correct 268 ms 97048 KB Output is correct
53 Correct 229 ms 93776 KB Output is correct
54 Correct 377 ms 119988 KB Output is correct
55 Correct 376 ms 98968 KB Output is correct