답안 #782031

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782031 2023-07-13T14:53:12 Z faruk 자동 인형 (IOI18_doll) C++17
53 / 100
89 ms 13120 KB
#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

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();
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 38 ms 8292 KB Output is correct
3 Correct 32 ms 7092 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 8 ms 3796 KB Output is correct
6 Correct 48 ms 10964 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 38 ms 8292 KB Output is correct
3 Correct 32 ms 7092 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 8 ms 3796 KB Output is correct
6 Correct 48 ms 10964 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 50 ms 8040 KB Output is correct
9 Correct 49 ms 10796 KB Output is correct
10 Correct 60 ms 12448 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 38 ms 8292 KB Output is correct
3 Correct 32 ms 7092 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 8 ms 3796 KB Output is correct
6 Correct 48 ms 10964 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 50 ms 8040 KB Output is correct
9 Correct 49 ms 10796 KB Output is correct
10 Correct 60 ms 12448 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 300 KB Output is correct
14 Correct 67 ms 12480 KB Output is correct
15 Correct 35 ms 6720 KB Output is correct
16 Correct 59 ms 10132 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 65 ms 12316 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 37 ms 5340 KB Output is correct
3 Partially correct 49 ms 9872 KB Output is partially correct
4 Partially correct 53 ms 10148 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 37 ms 5340 KB Output is correct
3 Partially correct 49 ms 9872 KB Output is partially correct
4 Partially correct 53 ms 10148 KB Output is partially correct
5 Partially correct 75 ms 12064 KB Output is partially correct
6 Partially correct 77 ms 12520 KB Output is partially correct
7 Partially correct 80 ms 12324 KB Output is partially correct
8 Partially correct 77 ms 12848 KB Output is partially correct
9 Partially correct 49 ms 8444 KB Output is partially correct
10 Partially correct 89 ms 12360 KB Output is partially correct
11 Partially correct 89 ms 13120 KB Output is partially correct
12 Partially correct 48 ms 8788 KB Output is partially correct
13 Partially correct 51 ms 8324 KB Output is partially correct
14 Partially correct 50 ms 8228 KB Output is partially correct
15 Partially correct 48 ms 8000 KB Output is partially correct
16 Partially correct 1 ms 468 KB Output is partially correct
17 Partially correct 40 ms 7148 KB Output is partially correct
18 Partially correct 40 ms 7200 KB Output is partially correct
19 Partially correct 44 ms 7524 KB Output is partially correct
20 Partially correct 58 ms 9772 KB Output is partially correct
21 Partially correct 66 ms 11552 KB Output is partially correct
22 Partially correct 53 ms 9132 KB Output is partially correct