Submission #1111903

# Submission time Handle Problem Language Result Execution time Memory
1111903 2024-11-13T10:08:19 Z epicci23 Mechanical Doll (IOI18_doll) C++17
0 / 100
248 ms 262144 KB
#include "bits/stdc++.h"
#include "doll.h"
//#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
using namespace std;

vector<int> x,y,state,hm;
int p=0,p2=0;
void give_index(int rt,int l,int r){
  if(l==r) return;
  x[rt] = (++p) * -1;
  y[rt] = (++p) * -1;
  int mid = (l+r)/2;
  give_index(x[rt],l,mid),give_index(y[rt],mid+1,r);
}

void make_leaf(int rt){
  if(state[rt]==0){
    if(x[rt]==-1) x[rt]=hm[p2++];
    else make_leaf(x[rt]);
  }
  else{
    if(y[rt]==-1) y[rt]=hm[p2++];
    else make_leaf(y[rt]);
  }
  state[rt]^=1;
}

void create_circuit(int m, vector<int> a){
  int n = sz(a);
  vector<int> c(m+1);
  vector<int> adj[m+5];

  for(int i=0;i<n;i++){
    if(i==0) adj[0].push_back(a[i]);
    else adj[a[i-1]].push_back(a[i]);
  }
  adj[a.back()].push_back(0);

  for(int i=0;i<=m;i++){
    if(sz(adj[i])==0) c[i]=i;
    if(sz(adj[i])==1) c[i]=adj[i][0];
    else{
      int xd = sz(adj[i]);
      int leaf=1;
      while(leaf<xd) leaf<<=1;
      int nd = leaf - 1;
      for(int j=0;j<nd;j++){
        x.push_back(-1);
        y.push_back(-1);
        state.push_back(0);
      }
      c[i] = (++p) * -1;
      give_index(c[i],1,leaf/2);
      p2=0;
      hm=adj[i];
      for(int j=0;j<xd;j++) make_leaf(c[i]);
    }
  }

  answer(c, x, y);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Runtime error 17 ms 11076 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Runtime error 17 ms 11076 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Runtime error 17 ms 11076 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1784 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 248 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 248 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -