답안 #756191

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
756191 2023-06-11T09:41:30 Z boris_mihov 자동 인형 (IOI18_doll) C++17
53 / 100
677 ms 39700 KB
#include "doll.h"
#include <algorithm>
#include <iostream>
#include <cassert>
#include <numeric>
#include <vector>

typedef long long llong;
const int MAXN = 1000000 + 10;
const int MAXS = 1000000 + 10;
const int INF  = 1e9;

int n, m, cnt;
std::vector <int> x, y, c;
std::vector <int> g[MAXN];
int perm[MAXN];
int treeRoot;

void rec(int l, int r, int node, int root)
{
    if (l + 1 == r)
    {
        if (perm[l] < g[node].size()) y[root - 1] = g[node][perm[l]];
        else y[root - 1] = -treeRoot;

        if (perm[r] < g[node].size()) x[root - 1] = g[node][perm[r]];
        else x[root - 1] = -treeRoot;
        return;
    }

    int mid = (l + r) / 2;
    x.push_back(0);
    x.push_back(0);
    y.push_back(0);
    y.push_back(0);
    cnt += 2;

    y[root - 1] = -(cnt - 1);
    x[root - 1] = -cnt;
    rec(l, mid, node, -y[root - 1]);
    rec(mid + 1, r, node, -x[root - 1]);
}

int reversed(int x, int bits)
{
    int res = 0;
    for (int i = 0 ; i < bits ; ++i)
    {
        if (x & (1 << i))
        {
            res |= (1 << bits - 1 - i);
        }
    }

    return res;
}

void create_circuit(int M, std::vector <int> A)
{
    m = M; n = A.size(); A.push_back(0);
    for (int i = 1 ; i <= n ; ++i)
    {   
        g[A[i - 1]].push_back(A[i]);
    }

    c.resize(m + 1); c[0] = A[0];
    for (int i = 1 ; i <= m ; ++i)
    {
        if (g[i].empty())
        {
            continue;
        }

        if (g[i].size() == 1)
        {
            c[i] = g[i][0];
        } else
        {
            int sz = 1, bits = 0;
            while (sz < g[i].size())
            {
                sz <<= 1;
                bits++;
            }

            c[i] = -(++cnt);
            x.push_back(0);
            y.push_back(0);
            std::reverse(g[i].begin(), g[i].end());
            std::iota(perm, perm + sz, 0);
            std::sort(perm, perm + sz, [&](int x, int y)
            {
                return reversed(x, bits) < reversed(y, bits);
            });

            treeRoot = cnt;
            rec(0, sz - 1, i, cnt);
        }
    }

    assert(x.size() <= 2 * n);
    answer(c, x, y);
}

Compilation message

doll.cpp: In function 'void rec(int, int, int, int)':
doll.cpp:23:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         if (perm[l] < g[node].size()) y[root - 1] = g[node][perm[l]];
      |             ~~~~~~~~^~~~~~~~~~~~~~~~
doll.cpp:26:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         if (perm[r] < g[node].size()) x[root - 1] = g[node][perm[r]];
      |             ~~~~~~~~^~~~~~~~~~~~~~~~
doll.cpp: In function 'int reversed(int, int)':
doll.cpp:51:35: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   51 |             res |= (1 << bits - 1 - i);
      |                          ~~~~~~~~~^~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:80:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |             while (sz < g[i].size())
      |                    ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from doll.cpp:4:
doll.cpp:101:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  101 |     assert(x.size() <= 2 * n);
      |            ~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23792 KB Output is correct
2 Correct 35 ms 27520 KB Output is correct
3 Correct 33 ms 27204 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 20 ms 24916 KB Output is correct
6 Correct 45 ms 29124 KB Output is correct
7 Correct 12 ms 23672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23792 KB Output is correct
2 Correct 35 ms 27520 KB Output is correct
3 Correct 33 ms 27204 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 20 ms 24916 KB Output is correct
6 Correct 45 ms 29124 KB Output is correct
7 Correct 12 ms 23672 KB Output is correct
8 Correct 55 ms 29916 KB Output is correct
9 Correct 59 ms 30344 KB Output is correct
10 Correct 89 ms 33472 KB Output is correct
11 Correct 13 ms 23764 KB Output is correct
12 Correct 14 ms 23792 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23792 KB Output is correct
2 Correct 35 ms 27520 KB Output is correct
3 Correct 33 ms 27204 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 20 ms 24916 KB Output is correct
6 Correct 45 ms 29124 KB Output is correct
7 Correct 12 ms 23672 KB Output is correct
8 Correct 55 ms 29916 KB Output is correct
9 Correct 59 ms 30344 KB Output is correct
10 Correct 89 ms 33472 KB Output is correct
11 Correct 13 ms 23764 KB Output is correct
12 Correct 14 ms 23792 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 94 ms 35304 KB Output is correct
15 Correct 55 ms 29560 KB Output is correct
16 Correct 79 ms 32484 KB Output is correct
17 Correct 12 ms 23740 KB Output is correct
18 Correct 14 ms 23772 KB Output is correct
19 Correct 13 ms 23780 KB Output is correct
20 Correct 88 ms 33968 KB Output is correct
21 Correct 13 ms 23764 KB Output is correct
22 Correct 15 ms 23696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 13 ms 23720 KB Output is partially correct
2 Correct 318 ms 30292 KB Output is correct
3 Partially correct 673 ms 32664 KB Output is partially correct
4 Partially correct 677 ms 34448 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 13 ms 23720 KB Output is partially correct
2 Correct 318 ms 30292 KB Output is correct
3 Partially correct 673 ms 32664 KB Output is partially correct
4 Partially correct 677 ms 34448 KB Output is partially correct
5 Partially correct 112 ms 36880 KB Output is partially correct
6 Partially correct 129 ms 38464 KB Output is partially correct
7 Partially correct 126 ms 37832 KB Output is partially correct
8 Partially correct 140 ms 38880 KB Output is partially correct
9 Partially correct 614 ms 33840 KB Output is partially correct
10 Partially correct 650 ms 39324 KB Output is partially correct
11 Partially correct 438 ms 39700 KB Output is partially correct
12 Partially correct 280 ms 33816 KB Output is partially correct
13 Partially correct 87 ms 32400 KB Output is partially correct
14 Partially correct 87 ms 32032 KB Output is partially correct
15 Partially correct 76 ms 31640 KB Output is partially correct
16 Partially correct 15 ms 24020 KB Output is partially correct
17 Partially correct 193 ms 31056 KB Output is partially correct
18 Partially correct 240 ms 31060 KB Output is partially correct
19 Partially correct 228 ms 32228 KB Output is partially correct
20 Partially correct 192 ms 35088 KB Output is partially correct
21 Partially correct 393 ms 37368 KB Output is partially correct
22 Partially correct 234 ms 34144 KB Output is partially correct