Submission #1067945

#TimeUsernameProblemLanguageResultExecution timeMemory
1067945IgnutMechanical Doll (IOI18_doll)C++17
6 / 100
55 ms12484 KiB
// Ignut

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

void create_circuit(int M, vector<int> A) {
    int N = A.size();
    vector<int> edges[M + 1];
    edges[0].push_back(A[0]);
    for (int i = 0; i + 1 < N; i ++)
        edges[A[i]].push_back(A[i + 1]);
    edges[A.back()].push_back(0);

    vector<int> C(M + 1);
    int nextSwitch = -1;
    vector<int> X, Y;
    for (int i = 0; i <= M; i ++) {
        if (edges[i].empty()) {
            C[i] = i; continue;
        }
        if (edges[i].size() == 1) {
            C[i] = edges[i][0]; continue;
        }
        vector<int> sw;
        for (int j = 0; j < edges[i].size() - 1; j ++) {
            sw.push_back(nextSwitch --);
        }
        C[i] = sw.front();
        for (int j = 0; j < sw.size(); j ++) {
            X.push_back(edges[i][j]);
            if (j + 1 == sw.size())
                Y.push_back(edges[i][j + 1]);
            else
                Y.push_back(sw[j + 1]);
        }
        // cerr << i << " : " << sw.size() << '\n';
    }
    answer(C, X, Y);
    return;
}


/*
4 4
1 2 1 3
*/

Compilation message (stderr)

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:29:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for (int j = 0; j < edges[i].size() - 1; j ++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~
doll.cpp:33:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for (int j = 0; j < sw.size(); j ++) {
      |                         ~~^~~~~~~~~~~
doll.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |             if (j + 1 == sw.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...