Submission #1060809

# Submission time Handle Problem Language Result Execution time Memory
1060809 2024-08-15T23:10:00 Z ArthuroWich Mechanical Doll (IOI18_doll) C++17
9 / 100
256 ms 38480 KB
#include "doll.h"
#include<bits/stdc++.h>
using namespace std;
struct node {
    int l = -1, r = -1, y = 0, valid = 1, d = 0;
};
int timer = 2, dep;
vector<int> x, y;
node tree[800005];
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 == -1 && tree[n].r == -1) {
            tree[n].valid = 0;
        }
        if (tree[n].l == -1) {
            tree[n].l = -1;
        } 
        if (tree[n].r == -1) {
            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];
    vector<set<int>> edges(m+1), edgesin(m+1);
    edgesin[a.front()].insert(0);
    edges[a.back()].insert(0);
    for (int i = 1; i < a.size(); i++) {
        edges[a[i-1]].insert(a[i]);
        edgesin[a[i]].insert(a[i-1]);
    }
    vector<int> c = {};
    a.push_back(0);
    for (int i = 0; i < a.size()-1; i++) {
        if (edges[a[i]].size() == 0) {
            d[a[i]] = 0;
        } else if (edges[a[i]].size() == 1) {
            d[a[i]] = a[i+1];
        } else {
            d[a[i]] = -1;
        }
    }
    a.pop_back();
    for (int i : a) {
        if (edgesin[i].size() != 1) {
            c.push_back(i);
        } else if (edgesin[i].size() == 1) {
            if (d[*edgesin[i].begin()] == -1) {
                c.push_back(i);
            }
            d[i] = -1;
        }
    }
    a = c;
    int n = a.size(), s;
    if (n != 0) {
        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]);
            } else {
                create(1, 0, -1);
            }
        }
        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:68:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for (int i = 1; i < a.size(); i++) {
      |                     ~~^~~~~~~~~~
doll.cpp:74:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for (int i = 0; i < a.size()-1; i++) {
      |                     ~~^~~~~~~~~~~~
doll.cpp:101:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |             if (i < a.size()) {
      |                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB wrong motion
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB wrong motion
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB wrong motion
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 1 ms 348 KB wrong motion
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 348 KB Output is partially correct
2 Correct 55 ms 9900 KB Output is correct
3 Partially correct 106 ms 14328 KB Output is partially correct
4 Partially correct 108 ms 15680 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 348 KB Output is partially correct
2 Correct 55 ms 9900 KB Output is correct
3 Partially correct 106 ms 14328 KB Output is partially correct
4 Partially correct 108 ms 15680 KB Output is partially correct
5 Partially correct 256 ms 38480 KB Output is partially correct
6 Partially correct 201 ms 36672 KB Output is partially correct
7 Partially correct 200 ms 37184 KB Output is partially correct
8 Partially correct 207 ms 35652 KB Output is partially correct
9 Partially correct 99 ms 14336 KB Output is partially correct
10 Incorrect 137 ms 21576 KB wrong motion
11 Halted 0 ms 0 KB -