Submission #297648

# Submission time Handle Problem Language Result Execution time Memory
297648 2020-09-11T17:17:13 Z davi_bart Mechanical Doll (IOI18_doll) C++14
53 / 100
147 ms 13216 KB
#include<bits/stdc++.h>
#include "doll.h"
using namespace std;
#define ll long long
#define fi first
#define se second

void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y);

void create_circuit(int M, std::vector<int> A) {
  int N = A.size();
  std::vector<int> C(M+1,0);
  vector<int> X,Y;

  vector<int> volte[M+2];
  vector<bool> vis(M+2,0);
  A.push_back(0);
  for(int i=0;i<A.size()-1;i++){
      volte[A[i]].push_back(A[i+1]);
  }
  C[0]=A[0];
  int S=1;
  for(int i=0;i<A.size()-1;i++){
    int x=A[i];
    if(volte[x].size()>=2){
      if(vis[x])continue;
      vis[x]=1;
      int y=volte[x].size();
      int lg=31-__builtin_clz(y);
      if((1<<lg)!=y)lg++;
      //cout<<lg<<endl;
      vector<int> k(1<<lg,0);
      for(int i=0;i<lg;i++){
        for(int j=0;j<(1<<lg);j+=(1<<(lg-i))){
          k[j+(1<<(lg-i-1))]=k[j]+(1<<i);
        }
      }
      C[x]=-S;
      int q=volte[x].back();
      volte[x].pop_back();
      while(volte[x].size()<(1<<lg))volte[x].push_back(-S);
      volte[x].pop_back();
      volte[x].push_back(q);
      //for(int a:volte[x])cout<<a<<" ";
      //cout<<endl;
      int s=S;
      for(int i=1;i<(1<<lg);i++){
        if(i<(1<<(lg-1))){
          X.push_back(-(2*i+s-1));
          Y.push_back(-(2*i+s));
        }else{
          X.push_back(volte[x][k[2*i-(1<<lg)]]);
          Y.push_back(volte[x][k[2*i+1-(1<<lg)]]);
        }
        S++;
      }
      continue;
    }
    C[x]=A[i+1];
  }
  answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:18:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |   for(int i=0;i<A.size()-1;i++){
      |               ~^~~~~~~~~~~
doll.cpp:23:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for(int i=0;i<A.size()-1;i++){
      |               ~^~~~~~~~~~~
doll.cpp:41:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |       while(volte[x].size()<(1<<lg))volte[x].push_back(-S);
      |             ~~~~~~~~~~~~~~~^~~~~~~~
doll.cpp:11:7: warning: unused variable 'N' [-Wunused-variable]
   11 |   int N = A.size();
      |       ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 34 ms 6332 KB Output is correct
3 Correct 28 ms 5196 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 14 ms 3788 KB Output is correct
6 Correct 47 ms 7748 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 34 ms 6332 KB Output is correct
3 Correct 28 ms 5196 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 14 ms 3788 KB Output is correct
6 Correct 47 ms 7748 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 57 ms 7684 KB Output is correct
9 Correct 82 ms 8768 KB Output is correct
10 Correct 131 ms 11900 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 34 ms 6332 KB Output is correct
3 Correct 28 ms 5196 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 14 ms 3788 KB Output is correct
6 Correct 47 ms 7748 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 57 ms 7684 KB Output is correct
9 Correct 82 ms 8768 KB Output is correct
10 Correct 131 ms 11900 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 117 ms 11452 KB Output is correct
15 Correct 66 ms 6680 KB Output is correct
16 Correct 98 ms 8740 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 121 ms 10792 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 2 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 204 KB Output is partially correct
2 Correct 46 ms 6308 KB Output is correct
3 Partially correct 74 ms 8428 KB Output is partially correct
4 Partially correct 87 ms 9392 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 204 KB Output is partially correct
2 Correct 46 ms 6308 KB Output is correct
3 Partially correct 74 ms 8428 KB Output is partially correct
4 Partially correct 87 ms 9392 KB Output is partially correct
5 Partially correct 147 ms 12060 KB Output is partially correct
6 Partially correct 126 ms 12652 KB Output is partially correct
7 Partially correct 126 ms 12436 KB Output is partially correct
8 Partially correct 117 ms 12744 KB Output is partially correct
9 Partially correct 71 ms 10084 KB Output is partially correct
10 Partially correct 113 ms 13216 KB Output is partially correct
11 Partially correct 122 ms 13104 KB Output is partially correct
12 Partially correct 77 ms 9288 KB Output is partially correct
13 Partially correct 81 ms 8184 KB Output is partially correct
14 Partially correct 85 ms 8144 KB Output is partially correct
15 Partially correct 78 ms 7916 KB Output is partially correct
16 Partially correct 3 ms 460 KB Output is partially correct
17 Partially correct 64 ms 7124 KB Output is partially correct
18 Partially correct 62 ms 7240 KB Output is partially correct
19 Partially correct 65 ms 7504 KB Output is partially correct
20 Partially correct 114 ms 9900 KB Output is partially correct
21 Partially correct 101 ms 11688 KB Output is partially correct
22 Partially correct 87 ms 9384 KB Output is partially correct