Submission #1060788

# Submission time Handle Problem Language Result Execution time Memory
1060788 2024-08-15T22:46:11 Z ArthuroWich Mechanical Doll (IOI18_doll) C++17
11 / 100
201 ms 37108 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[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 == 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];
    vector<set<int>> edges(m+1), edgesin(m+1);
    d[0] = a.front();
    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 = {};
    for (int i = 0; i < a.size(); 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;
        }
    }
    for (int i : a) {
        if (edgesin[i].size() != 1) {
            c.push_back(i);
        }
    }
    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, 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:69:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     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(); i++) {
      |                     ~~^~~~~~~~~~
doll.cpp:95:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |             if (i < a.size()) {
      |                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 24 ms 18008 KB Output is correct
3 Correct 21 ms 14428 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 10 ms 10840 KB Output is correct
6 Correct 45 ms 21588 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 24 ms 18008 KB Output is correct
3 Correct 21 ms 14428 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 10 ms 10840 KB Output is correct
6 Correct 45 ms 21588 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 100 ms 27596 KB wrong motion
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 24 ms 18008 KB Output is correct
3 Correct 21 ms 14428 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 10 ms 10840 KB Output is correct
6 Correct 45 ms 21588 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 100 ms 27596 KB wrong motion
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB wrong motion
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 348 KB Output is partially correct
2 Correct 51 ms 7768 KB Output is correct
3 Partially correct 98 ms 13296 KB Output is partially correct
4 Partially correct 101 ms 13996 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 348 KB Output is partially correct
2 Correct 51 ms 7768 KB Output is correct
3 Partially correct 98 ms 13296 KB Output is partially correct
4 Partially correct 101 ms 13996 KB Output is partially correct
5 Partially correct 188 ms 37108 KB Output is partially correct
6 Partially correct 188 ms 35060 KB Output is partially correct
7 Partially correct 201 ms 35772 KB Output is partially correct
8 Partially correct 186 ms 34032 KB Output is partially correct
9 Partially correct 99 ms 13300 KB Output is partially correct
10 Incorrect 133 ms 19792 KB wrong motion
11 Halted 0 ms 0 KB -