Submission #297511

#TimeUsernameProblemLanguageResultExecution timeMemory
297511eohomegrownappsMechanical Doll (IOI18_doll)C++14
22.33 / 100
115 ms7724 KiB
#include "doll.h" #include <bits/stdc++.h> using namespace std; vector<vector<int>> adjlist; vector<int> exitto; vector<int> switchxto; vector<int> switchyto; int sind = 0; // level 0 -- base //int lind = -1; int finale = 0; int create(int parent, int level, int num, const vector<int> &seq, int s, int e){ // returns index of switch //cout<<"make switch "<<-1-sind<<" at level "<<level<<'\n'<<" with num "<<num<<'\n'; /*for (int i : seq){ cout<<i<<' '; }cout<<'\n'; cout<<seq.size()<<'\n';*/ if (num==0){ //cout<<"num is 0"<<'\n'; if (level==0){ return (e==finale)?0:-1; } // make something that counts (1<<level) times before returning int firstswitch = sind; for (int i = 0; i<level-1; i++){ // make switch // parent: prevconnect // x: -1 // y: sind+1 switchxto.push_back(1e9); switchyto.push_back(1e9); switchxto[sind]=-1; switchyto[sind]=-1-(sind+1); sind++; } switchxto.push_back(1e9); switchyto.push_back(1e9); switchxto[sind]=-1; switchyto[sind]=(e==finale)?0:-1; //lind=sind; sind++; return -1-firstswitch; } if (level==0){ //numleft--; return seq[0]; } int switchtouse = sind; switchxto.push_back(1e9); switchyto.push_back(1e9); sind++; int sendleft = min((1<<(level-1)),num); int sendright = max(0,num-(1<<(level-1))); vector<int> left; vector<int> right; int ptr = 0; for (int i = 0; i<sendright; i++){ left.push_back(seq[ptr]); right.push_back(seq[ptr+1]); ptr+=2; } for (int i = sendright; i<sendleft; i++){ left.push_back(seq[ptr]); ptr++; } int cl = create(switchtouse,level-1,sendleft,left,s,(s+e)/2); int cr = create(switchtouse,level-1,sendright,right,(s+e)/2+1,e); switchxto[switchtouse]=cl; switchyto[switchtouse]=cr; return -1-switchtouse; } void create_circuit(int m, std::vector<int> a) { int n = a.size(); if (n%2!=1){ n++; } int level = log2(n-1)+1; finale = (1<<level)-1; create(0,level,a.size(),a,0,(1<<level)-1); /*if (lind!=-1){ switchyto[lind]=0; }*/ exitto.resize(m+1,-1); /*for (int i : switchxto){ cout<<i<<' '; }cout<<'\n'; for (int i : switchyto){ cout<<i<<' '; }cout<<'\n';*/ answer(exitto,switchxto,switchyto); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...