Submission #146406

# Submission time Handle Problem Language Result Execution time Memory
146406 2019-08-23T20:14:04 Z mperos Unscrambling a Messy Bug (IOI16_messy) C++14
100 / 100
4 ms 632 KB
#include <bits/stdc++.h>
#include <vector>
#include "messy.h"

using namespace std;

void generate_strings(int n, int l, int r) {
    if(l == r) return;

    string s;
    for(int i = 0; i < n; i++)
        s += "0";
    for(int i = l; i <= r; i++)
        s[i] = '1';
    int mid = (l + r) / 2;
    for(int i = l; i <= mid; i++) {
        s[i] = '0';
        add_element(s);
        s[i] = '1';
    }

    generate_strings(n, l, mid);
    generate_strings(n, mid + 1, r);
}



void query(int n, int l, int r, vector<int> v, vector <int>& p) {
    if(l == r){
        p[l] = v[0];
        return;
    }

    vector <int> left;
    vector <int> right;

    string s;
    for(int i = 0; i < n; i++)
        s += "0";
    for(int i : v)
        s[i] = '1';
    int mid = (l + r) / 2;
    for(int i : v) {
        s[i] = '0';
        bool val = check_element(s);
        if(val == true)
            left.push_back(i);
        else
            right.push_back(i);
        s[i] = '1';
    }

    query(n, l, mid, left, p);
    query(n, mid + 1, r, right, p);
}

vector<int> restore_permutation(int n, int w, int r) {
    vector <int> v;
    vector <int> p(n);
    vector <int> pos(n);
    generate_strings(n, 0, n - 1);
    compile_set();
    for(int i = 0; i < n; i++)
        v.push_back(i);
    query(n, 0, n - 1, v, p);
    for(int i = 0; i < n; i++)
        pos[p[i]] = i;

    return pos;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n = 8
2 Correct 2 ms 376 KB n = 8
3 Correct 2 ms 256 KB n = 8
4 Correct 2 ms 376 KB n = 8
5 Correct 3 ms 376 KB n = 8
6 Correct 2 ms 376 KB n = 8
7 Correct 2 ms 376 KB n = 8
8 Correct 3 ms 380 KB n = 8
9 Correct 2 ms 256 KB n = 8
10 Correct 2 ms 376 KB n = 8
11 Correct 2 ms 376 KB n = 8
12 Correct 2 ms 376 KB n = 8
13 Correct 2 ms 376 KB n = 8
14 Correct 2 ms 256 KB n = 8
15 Correct 2 ms 392 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n = 32
2 Correct 2 ms 376 KB n = 32
3 Correct 2 ms 376 KB n = 32
4 Correct 2 ms 376 KB n = 32
5 Correct 2 ms 376 KB n = 32
6 Correct 2 ms 504 KB n = 32
7 Correct 2 ms 376 KB n = 32
8 Correct 3 ms 400 KB n = 32
9 Correct 2 ms 376 KB n = 32
10 Correct 4 ms 376 KB n = 32
11 Correct 2 ms 376 KB n = 32
12 Correct 3 ms 508 KB n = 32
13 Correct 3 ms 376 KB n = 32
14 Correct 3 ms 380 KB n = 32
15 Correct 2 ms 376 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n = 32
2 Correct 2 ms 380 KB n = 32
3 Correct 2 ms 376 KB n = 32
4 Correct 2 ms 376 KB n = 32
5 Correct 2 ms 348 KB n = 32
6 Correct 2 ms 376 KB n = 32
7 Correct 2 ms 376 KB n = 32
8 Correct 2 ms 376 KB n = 32
9 Correct 2 ms 376 KB n = 32
10 Correct 2 ms 376 KB n = 32
11 Correct 3 ms 376 KB n = 32
12 Correct 2 ms 376 KB n = 32
13 Correct 2 ms 376 KB n = 32
14 Correct 2 ms 376 KB n = 32
15 Correct 2 ms 376 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB n = 128
2 Correct 4 ms 504 KB n = 128
3 Correct 4 ms 504 KB n = 128
4 Correct 4 ms 504 KB n = 128
5 Correct 4 ms 504 KB n = 128
6 Correct 4 ms 504 KB n = 128
7 Correct 4 ms 504 KB n = 128
8 Correct 4 ms 504 KB n = 128
9 Correct 4 ms 504 KB n = 128
10 Correct 4 ms 504 KB n = 128
11 Correct 4 ms 488 KB n = 128
12 Correct 4 ms 504 KB n = 128
13 Correct 4 ms 504 KB n = 128
14 Correct 4 ms 504 KB n = 128
15 Correct 4 ms 504 KB n = 128
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB n = 128
2 Correct 4 ms 504 KB n = 128
3 Correct 4 ms 504 KB n = 128
4 Correct 4 ms 476 KB n = 128
5 Correct 4 ms 504 KB n = 128
6 Correct 4 ms 504 KB n = 128
7 Correct 4 ms 484 KB n = 128
8 Correct 4 ms 508 KB n = 128
9 Correct 4 ms 504 KB n = 128
10 Correct 4 ms 508 KB n = 128
11 Correct 4 ms 504 KB n = 128
12 Correct 4 ms 504 KB n = 128
13 Correct 4 ms 508 KB n = 128
14 Correct 4 ms 632 KB n = 128
15 Correct 4 ms 504 KB n = 128