Submission #286330

#TimeUsernameProblemLanguageResultExecution timeMemory
286330ne4eHbKaMechanical Doll (IOI18_doll)C++17
28 / 100
253 ms26232 KiB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;

namespace solution {

vi c, x, y;
int s;

int swicch(int e, list<int> &t, int p) {
    p >>= 1;
    int i = s++;
    x.push_back(0);
    y.push_back(0);
    if(e + t.size() == 2) {
        if(e == 1) {
            x[i] = -1;
            y[i] = t.back();
        } else {
            x[i] = t.front();
            y[i] = t.back();
        }
        return -(i + 1);
    }
    if(e >= p) {
        x[i] = -1;
        y[i] = swicch(e - p, t, p);
        return -(i + 1);
    }
    list<int> a, b;
    int it = 0;
    for(int i : t) {
        if(b.size() < e) {
            b.push_back(i);
        } else {
            (++it & 1 ? a : b).push_back(i);
        }
    }
    x[i] = swicch(e, a, p);
    y[i] = swicch(0, b, p);
    return -(i + 1);
}

}

void create_circuit (int m, vi a) {
    using namespace solution;
    int n = a.size();
    s = 0;
    x.clear(); x.reserve(n * 4);
    y.clear(); y.reserve(n * 4);
    if(n == 1) {
        c.assign(m + 1, 0);
        c[0] = a[0];
        answer(c, x, y);
        return;
    }
    c.assign(m + 1, -1);
    c[0] = a[0];
    list<int> f;
    for(int i = 1; i < n; ++i) f.push_back(a[i]);
    f.push_back(0);
    int e = 0;
    for(; __builtin_popcount(e + n) > 1; ++e);
    swicch(e, f, e + f.size());
    answer(c, x, y);
}

Compilation message (stderr)

doll.cpp: In function 'int solution::swicch(int, std::__cxx11::list<int>&, int)':
doll.cpp:34:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::list<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |         if(b.size() < e) {
      |            ~~~~~~~~~^~~
#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...