Submission #658244

# Submission time Handle Problem Language Result Execution time Memory
658244 2022-11-12T14:11:36 Z benjaminkleyn Unscrambling a Messy Bug (IOI16_messy) C++17
100 / 100
2 ms 496 KB
#include <bits/stdc++.h>
#include "messy.h"
using namespace std;
typedef long long ll;

vector<int> res;
void find(const int &l, const int &r, vector<int> &idx, const int &n)
{
    /* // debug
    cout << "(l, r) = (" << l << ", " << r << ")\n";
    cout << "idx = [";
    for (int x : idx)
        cout << x << " ";
    cout << "]\n";
    */

    if (l == r)
    {
        res[idx[0]] = l;
        return;
    }
    // assuming we know the indices in idx are mapped to the range [l, r]
    vector<int> left_idx, right_idx;
    for (const int &i : idx)
    {
        string s(n, '1');
        for (const int &j : idx)
            if (j != i)
                s[j] = '0';

        if (check_element(s))
            left_idx.push_back(i);
        else
            right_idx.push_back(i);
    }
    idx.clear();
    find(l, (l + r) / 2, left_idx, n);
    find((l + r) / 2 + 1, r, right_idx, n);
}


vector<int> restore_permutation(int n, int w, int r) 
{
    // consider a number of the form
    //
    // 10000000
    // 01000000
    // 00100000
    // 00010000
    //
    // or something like that, so we can halve the searching space.

    string s;
    for (int k = 1; k < n; k *= 2)
    {
        // cout << k << '\n';
        for (int i = 0; i < n; i += 2 * k)
        {
            s = string(n, '1');
            for (int j = i; j < i + 2 * k; j++)
                s[j] = '0';
            for (int j = i; j < i + k; j++)
            {
                s[j] = '1';
                // cout << s << '\n';
                add_element(s);
                s[j] = '0';
            }
        }
    }
    s = "";

    compile_set();

    vector<int> idx(n);
    iota(idx.begin(), idx.end(), 0);

    res.resize(n);
    find(0, n - 1, idx, n);

    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 8
2 Correct 0 ms 212 KB n = 8
3 Correct 0 ms 212 KB n = 8
4 Correct 0 ms 212 KB n = 8
5 Correct 1 ms 212 KB n = 8
6 Correct 1 ms 212 KB n = 8
7 Correct 1 ms 212 KB n = 8
8 Correct 1 ms 212 KB n = 8
9 Correct 0 ms 212 KB n = 8
10 Correct 0 ms 212 KB n = 8
11 Correct 0 ms 212 KB n = 8
12 Correct 0 ms 212 KB n = 8
13 Correct 1 ms 212 KB n = 8
14 Correct 0 ms 212 KB n = 8
15 Correct 0 ms 212 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 32
2 Correct 0 ms 212 KB n = 32
3 Correct 1 ms 212 KB n = 32
4 Correct 1 ms 212 KB n = 32
5 Correct 1 ms 212 KB n = 32
6 Correct 1 ms 212 KB n = 32
7 Correct 0 ms 212 KB n = 32
8 Correct 0 ms 212 KB n = 32
9 Correct 0 ms 212 KB n = 32
10 Correct 0 ms 212 KB n = 32
11 Correct 1 ms 212 KB n = 32
12 Correct 1 ms 212 KB n = 32
13 Correct 1 ms 212 KB n = 32
14 Correct 1 ms 212 KB n = 32
15 Correct 1 ms 212 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 32
2 Correct 1 ms 212 KB n = 32
3 Correct 1 ms 212 KB n = 32
4 Correct 1 ms 212 KB n = 32
5 Correct 1 ms 212 KB n = 32
6 Correct 1 ms 212 KB n = 32
7 Correct 0 ms 212 KB n = 32
8 Correct 0 ms 212 KB n = 32
9 Correct 1 ms 212 KB n = 32
10 Correct 1 ms 212 KB n = 32
11 Correct 1 ms 212 KB n = 32
12 Correct 1 ms 212 KB n = 32
13 Correct 1 ms 212 KB n = 32
14 Correct 1 ms 212 KB n = 32
15 Correct 1 ms 212 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB n = 128
2 Correct 1 ms 468 KB n = 128
3 Correct 1 ms 468 KB n = 128
4 Correct 1 ms 468 KB n = 128
5 Correct 1 ms 468 KB n = 128
6 Correct 1 ms 468 KB n = 128
7 Correct 1 ms 496 KB n = 128
8 Correct 1 ms 468 KB n = 128
9 Correct 1 ms 468 KB n = 128
10 Correct 2 ms 468 KB n = 128
11 Correct 1 ms 468 KB n = 128
12 Correct 1 ms 468 KB n = 128
13 Correct 1 ms 468 KB n = 128
14 Correct 1 ms 468 KB n = 128
15 Correct 2 ms 468 KB n = 128
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB n = 128
2 Correct 1 ms 468 KB n = 128
3 Correct 1 ms 468 KB n = 128
4 Correct 1 ms 468 KB n = 128
5 Correct 2 ms 468 KB n = 128
6 Correct 1 ms 468 KB n = 128
7 Correct 1 ms 468 KB n = 128
8 Correct 1 ms 468 KB n = 128
9 Correct 1 ms 468 KB n = 128
10 Correct 2 ms 468 KB n = 128
11 Correct 2 ms 496 KB n = 128
12 Correct 2 ms 468 KB n = 128
13 Correct 1 ms 468 KB n = 128
14 Correct 2 ms 468 KB n = 128
15 Correct 1 ms 468 KB n = 128