Submission #782031

#TimeUsernameProblemLanguageResultExecution timeMemory
782031farukMechanical Doll (IOI18_doll)C++17
53 / 100
89 ms13120 KiB
#include "doll.h" #include <bits/stdc++.h> using namespace std; void set_idxs(int offset, int curr, int idx, int depth, int &max_node, vector<int> &targets, vector<int> &xs, vector<int> &ys) { if (curr >= max_node) { int par = (curr - 1) / 2; if (curr % 2) xs[par] = targets[idx]; else ys[par] = targets[idx]; return; } xs[curr] = -((curr + 1) * 2 - 1) - offset; ys[curr] = -((curr + 1) * 2) - offset; set_idxs(offset, (curr + 1) * 2 - 1, idx, depth + 1, max_node, targets, xs, ys); set_idxs(offset, (curr + 1) * 2, idx + (1 << depth), depth + 1, max_node, targets, xs, ys); } pair<vector<int>, vector<int> > getxy(int node, vector<int> targets, int offset) { // determine size of last_row int siz = 1, needed_nodes = 1; while (siz * 2 < targets.size()) siz *= 2, needed_nodes += siz; while (targets.size() < 2*siz) { targets.push_back(-offset); swap(targets[targets.size() - 1], targets[targets.size() - 2]); } vector<int> xs(needed_nodes); vector<int> ys(needed_nodes); set_idxs(offset, 0, 0, 0, needed_nodes, targets, xs, ys); return make_pair(xs, ys); } void create_circuit(int M, std::vector<int> A) { int N = A.size(); std::vector<int> C(M + 1); std::vector<int> X, Y; C[0] = A[0]; vector<vector<int> > targets(M + 1); for (int i = 0; i < A.size(); i++) { int next = i == A.size() - 1 ? 0 : A[i + 1]; targets[A[i]].push_back(next); } for (int i = 1; i <= M; i++) { if (targets[i].empty()) continue; C[i] = -(X.size() + 1); auto xandy = getxy(i, targets[i], X.size() + 1); for (int j = 0; j < xandy.first.size(); j++) X.push_back(xandy.first[j]), Y.push_back(xandy.second[j]); } answer(C, X, Y); }

Compilation message (stderr)

doll.cpp: In function 'std::pair<std::vector<int>, std::vector<int> > getxy(int, std::vector<int>, int)':
doll.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     while (siz * 2 < targets.size())
      |            ~~~~~~~~^~~~~~~~~~~~~~~~
doll.cpp:27:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |     while (targets.size() < 2*siz) {
      |            ~~~~~~~~~~~~~~~^~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for (int i = 0; i < A.size(); i++) {
      |                     ~~^~~~~~~~~~
doll.cpp:45:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         int next = i == A.size() - 1 ? 0 : A[i + 1];
      |                    ~~^~~~~~~~~~~~~~~
doll.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for (int j = 0; j < xandy.first.size(); j++)
      |                         ~~^~~~~~~~~~~~~~~~~~~~
doll.cpp:39:9: warning: unused variable 'N' [-Wunused-variable]
   39 |     int N = A.size();
      |         ^
#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...