답안 #1060719

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1060719 2024-08-15T21:11:18 Z ArthuroWich 자동 인형 (IOI18_doll) C++17
47 / 100
135 ms 14212 KB
#include "doll.h"
#include<bits/stdc++.h>
using namespace std;
struct node {
    int l = INT_MIN, r = INT_MIN, y = 0, valid = 1, d = 0;
};
int timer = 2, dep;
vector<int> x, y;
node tree[500005];
void build(int n, int d) {
    tree[n].d = d;
    if (dep-1 == d) {
        return;
    }
    tree[n].l = -timer;
    timer++;
    tree[n].r = -timer;
    timer++;
    build(-tree[n].l, d+1);
    build(-tree[n].r, d+1);
}
void create(int n, int d, int v) {
    if (dep-1 == d) {
        if (tree[n].y == 0) {
            tree[n].l = v;
        } else {
            tree[n].r = v;
        }
    } else {
        if (tree[n].y == 0) {
            create(-tree[n].l, d+1, v);
        } else {
            create(-tree[n].r, d+1, v);
        }
    }
    tree[n].y ^= 1;
}
void clean(int n, int d) {
    if (dep-1 == d) {
        if (tree[n].l == INT_MIN && tree[n].r == INT_MIN) {
            tree[n].valid = 0;
        }
        if (tree[n].l == INT_MIN) {
            tree[n].l = -1;
        } 
        if (tree[n].r == INT_MIN) {
            tree[n].r = -1;
        }
    } else {
        clean(-tree[n].l, d+1);
        clean(-tree[n].r, d+1);
        tree[n].valid |= tree[-tree[n].l].valid;
        tree[n].valid |= tree[-tree[n].r].valid;
        if (tree[-tree[n].l].valid == 0) {
            tree[n].l = -1;
        }
        if (tree[-tree[n].r].valid == 0) {
            tree[n].r = -1;
        } 
    }
}
void create_circuit(int m, vector<int> a) {
    vector<int> d(m+1, 0);
    d[0] = a[0];
    d[a[0]] = -1;
    int n = a.size(), s;
    dep = ceil(log2(n));
    s = 1 << dep;
    build(1, 0);
    for (int i = 1; i < s; i++) {
        if (i < a.size()) {
            create(1, 0, a[i]);
            d[a[i]] = -1;
        } else {
            create(1, 0, INT_MIN);
        }
    }
    create(1, 0, 0);
    clean(1, 0);
    //for (int i = 1; i < s; i++) {
    //    cout << tree[i].l << " " << tree[i].r << endl;
    //}
    //cout << endl;
    for (int i = 1; i < s; i++) {
        if (tree[i].valid == 0) {
            continue;
        }
        x.push_back(tree[i].l);
        y.push_back(tree[i].r);
    }
    answer(d, x, y);
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:71:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         if (i < a.size()) {
      |             ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 348 KB Output is partially correct
2 Correct 52 ms 7228 KB Output is correct
3 Partially correct 107 ms 12844 KB Output is partially correct
4 Partially correct 113 ms 13504 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 348 KB Output is partially correct
2 Correct 52 ms 7228 KB Output is correct
3 Partially correct 107 ms 12844 KB Output is partially correct
4 Partially correct 113 ms 13504 KB Output is partially correct
5 Partially correct 110 ms 14212 KB Output is partially correct
6 Partially correct 103 ms 13988 KB Output is partially correct
7 Partially correct 101 ms 13968 KB Output is partially correct
8 Partially correct 104 ms 13916 KB Output is partially correct
9 Partially correct 114 ms 12864 KB Output is partially correct
10 Partially correct 102 ms 13816 KB Output is partially correct
11 Partially correct 135 ms 13424 KB Output is partially correct
12 Partially correct 95 ms 13408 KB Output is partially correct
13 Correct 73 ms 7368 KB Output is correct
14 Partially correct 128 ms 13488 KB Output is partially correct
15 Partially correct 94 ms 13488 KB Output is partially correct
16 Partially correct 3 ms 856 KB Output is partially correct
17 Correct 59 ms 7144 KB Output is correct
18 Correct 52 ms 7240 KB Output is correct
19 Partially correct 104 ms 13140 KB Output is partially correct
20 Partially correct 101 ms 13652 KB Output is partially correct
21 Partially correct 121 ms 13692 KB Output is partially correct
22 Partially correct 104 ms 13556 KB Output is partially correct