답안 #969902

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
969902 2024-04-25T19:01:31 Z BestCrazyNoob 자동 인형 (IOI18_doll) C++17
85.553 / 100
227 ms 18632 KB
#include "doll.h"
#include <vector>
#include <array>
#include <algorithm>

using namespace std;
constexpr int H = 19;

vector<vector<int>> graph;
vector<int> C, X, Y;
int nxt = -1;
array<vector<int>, H> pos;

void create(int curr, int sz, vector<int> v, int root, int h) {
    // For local vectors
    curr = -1-curr;

    if (sz == 2) {
        X[curr] = v.size() > 1 ? v[0] : root;
        Y[curr] = v.size() > 1 ? v[1] : v[0];
    } else {
        if (v.size() > sz/2) {
            X[curr] = nxt--;
            Y[curr] = nxt--;
            vector<int> i1(pos[h].end() - v.size(), pos[h].begin() + sz/2), i2(pos[h].begin() + sz/2, pos[h].end()), v1, v2;
            sort(i1.begin(), i1.end());
            sort(i2.begin(), i2.end());
            int i = 0, j = 0, x = 0;
            while (i < v1.size() || j < i2.size()) {
                if (i < i1.size() && (j == i2.size() || i1[i] < i2[j])) {
                    i1[i++] = x++;
                } else {
                    i2[j++] = x++;
                }
            }
            for (int i: i1) v1.push_back(v[i]);
            for (int i: i2) v2.push_back(v[i]);
            create(X[curr], sz/2, v1, root, h-1);
            create(Y[curr], sz/2, v2, root, h-1);
        } else {
            X[curr] = root;
            Y[curr] = nxt--;
            create(Y[curr], sz/2, v, root, h-1);
        }
    }
}

void calc_recur(vector<int> v, int h, int i) {
    if (v.size() == 1) {
        pos[h][i] = v[0];
        return;
    }
    vector<int> v1, v2;
    for (int i = 0; i < v.size(); i++) {
        if (i % 2 == 0) v1.push_back(v[i]);
        else v2.push_back(v[i]);
    }
    calc_recur(v1, h, i);
    calc_recur(v2, h, i + v2.size());
}

void create_circuit(int M, vector<int> A) {
    // SETUP
    for (int h = 0; h < H; h++) {
        pos[h].resize(1 << h);
        vector<int> v;
        v.resize(1 << h);
        for (int i = 0; i < (1 << h); i++) v[i] = i;
        calc_recur(v, h, 0);
    }
    
    const int N = A.size();
    graph.resize(M+1);
    int last = 0;
    for (int i = 0; i < N; i++) {
        graph[last].push_back(A[i]);
        last = A[i];
    }
    graph[last].push_back(0);

    C.resize(M+1);
    X.resize(400'000);
    Y.resize(400'000);
    for (int i = 0; i < M+1; i++) {
        if (graph[i].size() == 0) {
            C[i] = 0;
        } else if (graph[i].size() == 1) {
            C[i] = graph[i][0];
        } else {
            int sz = 1, h = 0;
            while (sz < graph[i].size()) {
                h++;
                sz *= 2;
            }
            C[i] = nxt--;
            create(C[i], sz, graph[i], C[i], h);
        }
    }
    X.resize(-1-nxt);
    Y.resize(-1-nxt);
    answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'void create(int, int, std::vector<int>, int, int)':
doll.cpp:22:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |         if (v.size() > sz/2) {
      |             ~~~~~~~~~^~~~~~
doll.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |             while (i < v1.size() || j < i2.size()) {
      |                    ~~^~~~~~~~~~~
doll.cpp:29:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |             while (i < v1.size() || j < i2.size()) {
      |                                     ~~^~~~~~~~~~~
doll.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |                 if (i < i1.size() && (j == i2.size() || i1[i] < i2[j])) {
      |                     ~~^~~~~~~~~~~
doll.cpp:30:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |                 if (i < i1.size() && (j == i2.size() || i1[i] < i2[j])) {
      |                                       ~~^~~~~~~~~~~~
doll.cpp: In function 'void calc_recur(std::vector<int>, int, int)':
doll.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:91:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |             while (sz < graph[i].size()) {
      |                    ~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 7484 KB Output is correct
2 Correct 100 ms 11752 KB Output is correct
3 Correct 99 ms 10672 KB Output is correct
4 Correct 93 ms 7808 KB Output is correct
5 Correct 91 ms 9452 KB Output is correct
6 Correct 104 ms 13132 KB Output is correct
7 Correct 92 ms 7532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 7484 KB Output is correct
2 Correct 100 ms 11752 KB Output is correct
3 Correct 99 ms 10672 KB Output is correct
4 Correct 93 ms 7808 KB Output is correct
5 Correct 91 ms 9452 KB Output is correct
6 Correct 104 ms 13132 KB Output is correct
7 Correct 92 ms 7532 KB Output is correct
8 Correct 119 ms 12980 KB Output is correct
9 Correct 118 ms 13948 KB Output is correct
10 Correct 134 ms 16444 KB Output is correct
11 Correct 83 ms 7620 KB Output is correct
12 Correct 85 ms 7556 KB Output is correct
13 Correct 92 ms 7612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 7484 KB Output is correct
2 Correct 100 ms 11752 KB Output is correct
3 Correct 99 ms 10672 KB Output is correct
4 Correct 93 ms 7808 KB Output is correct
5 Correct 91 ms 9452 KB Output is correct
6 Correct 104 ms 13132 KB Output is correct
7 Correct 92 ms 7532 KB Output is correct
8 Correct 119 ms 12980 KB Output is correct
9 Correct 118 ms 13948 KB Output is correct
10 Correct 134 ms 16444 KB Output is correct
11 Correct 83 ms 7620 KB Output is correct
12 Correct 85 ms 7556 KB Output is correct
13 Correct 92 ms 7612 KB Output is correct
14 Correct 174 ms 17128 KB Output is correct
15 Correct 130 ms 11408 KB Output is correct
16 Correct 145 ms 14308 KB Output is correct
17 Correct 82 ms 7528 KB Output is correct
18 Correct 83 ms 7568 KB Output is correct
19 Correct 89 ms 7568 KB Output is correct
20 Correct 149 ms 16448 KB Output is correct
21 Correct 84 ms 7620 KB Output is correct
22 Correct 82 ms 7536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 7616 KB Output is correct
2 Correct 83 ms 7612 KB Output is correct
3 Correct 93 ms 7552 KB Output is correct
4 Correct 85 ms 7612 KB Output is correct
5 Correct 83 ms 7616 KB Output is correct
6 Correct 83 ms 7612 KB Output is correct
7 Correct 81 ms 7476 KB Output is correct
8 Correct 83 ms 7620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 7608 KB Output is correct
2 Correct 167 ms 10740 KB Output is correct
3 Correct 176 ms 12316 KB Output is correct
4 Correct 227 ms 14808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 7608 KB Output is correct
2 Correct 167 ms 10740 KB Output is correct
3 Correct 176 ms 12316 KB Output is correct
4 Correct 227 ms 14808 KB Output is correct
5 Partially correct 177 ms 18632 KB Output is partially correct
6 Partially correct 171 ms 17896 KB Output is partially correct
7 Partially correct 168 ms 18128 KB Output is partially correct
8 Partially correct 175 ms 16868 KB Output is partially correct
9 Partially correct 166 ms 11676 KB Output is partially correct
10 Partially correct 198 ms 15836 KB Output is partially correct
11 Partially correct 171 ms 15332 KB Output is partially correct
12 Partially correct 135 ms 11760 KB Output is partially correct
13 Partially correct 137 ms 13560 KB Output is partially correct
14 Partially correct 143 ms 13856 KB Output is partially correct
15 Partially correct 136 ms 14064 KB Output is partially correct
16 Partially correct 85 ms 7616 KB Output is partially correct
17 Partially correct 132 ms 11504 KB Output is partially correct
18 Partially correct 135 ms 11504 KB Output is partially correct
19 Partially correct 135 ms 11496 KB Output is partially correct
20 Partially correct 158 ms 15020 KB Output is partially correct
21 Partially correct 178 ms 14576 KB Output is partially correct
22 Partially correct 161 ms 14528 KB Output is partially correct