Submission #159559

# Submission time Handle Problem Language Result Execution time Memory
159559 2019-10-23T08:36:48 Z rama_pang Unscrambling a Messy Bug (IOI16_messy) C++14
100 / 100
5 ms 636 KB
#include "messy.h"
#include <bits/stdc++.h>
using namespace std;

/*  Idea: Use Divide and Conquer, set each bits in interval le...ri to 1 once, adding it to data structure.
    For all bits outside interval, set it to 1.
    Then when checking, you can see which elemnts belong to interval le...mid and (mid + 1)...ri, then
    apply DnC normally.
*/

void add_permutation(int le, int ri, int N) {
    string element;
    for (int i = 0; i < N; i++) element.push_back('1');
    for (int i = le; i <= ri; i++) element[i - 1] = '0';
    if (le >= ri) return;

    int mid = (le + ri) / 2;
    for (int i = le; i <= mid; i++) {
        element[i - 1] = '1';
        add_element(element);
        element[i - 1] = '0';
    }

    add_permutation(le, mid, N);
    add_permutation(mid + 1, ri, N);

}

void get_permutation(int le, int ri, vector<int> forbidden, vector<int> &ans, int N) {
    string element;
    for (int i = 0; i < N; i++) element.push_back('0');
    for (auto i : forbidden) element[i - 1] = '1';

    if (le == ri) {
        for (int i = 0; i < N; i++) {
            if (element[i] == '0') {
                ans[i] = le - 1;
                return;
            }
        }
    }

    vector<int> left_forbidden = forbidden, right_forbidden = forbidden;
    for (int i = 1; i <= N; i++) {
        if (element[i - 1] == '1') continue;
        element[i - 1] = '1';
        if (check_element(element)) {
            right_forbidden.push_back(i);
        } else {
            left_forbidden.push_back(i);
        }
        element[i - 1] = '0';
    }

    int mid = (le + ri) / 2;
    get_permutation(le, mid, left_forbidden, ans, N);
    get_permutation(mid + 1, ri, right_forbidden, ans, N);

}

vector<int> restore_permutation(int n, int w, int r) {
    vector<int> res(n);
    add_permutation(1, n, n);
    compile_set();
    get_permutation(1, n, vector<int>(), res, n);
    
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB n = 8
2 Correct 2 ms 376 KB n = 8
3 Correct 2 ms 380 KB n = 8
4 Correct 2 ms 256 KB n = 8
5 Correct 2 ms 256 KB n = 8
6 Correct 2 ms 256 KB n = 8
7 Correct 2 ms 376 KB n = 8
8 Correct 2 ms 376 KB n = 8
9 Correct 2 ms 256 KB n = 8
10 Correct 2 ms 256 KB n = 8
11 Correct 2 ms 256 KB n = 8
12 Correct 2 ms 256 KB n = 8
13 Correct 2 ms 256 KB n = 8
14 Correct 2 ms 376 KB n = 8
15 Correct 2 ms 376 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 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 2 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 2 ms 376 KB n = 32
2 Correct 2 ms 376 KB n = 32
3 Correct 2 ms 376 KB n = 32
4 Correct 3 ms 396 KB n = 32
5 Correct 2 ms 376 KB n = 32
6 Correct 2 ms 376 KB n = 32
7 Correct 2 ms 376 KB n = 32
8 Correct 2 ms 360 KB n = 32
9 Correct 3 ms 380 KB n = 32
10 Correct 2 ms 376 KB n = 32
11 Correct 2 ms 376 KB n = 32
12 Correct 2 ms 380 KB n = 32
13 Correct 2 ms 256 KB n = 32
14 Correct 3 ms 376 KB n = 32
15 Correct 2 ms 344 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 5 ms 504 KB n = 128
4 Correct 4 ms 504 KB n = 128
5 Correct 5 ms 520 KB n = 128
6 Correct 4 ms 504 KB n = 128
7 Correct 4 ms 504 KB n = 128
8 Correct 4 ms 508 KB n = 128
9 Correct 5 ms 504 KB n = 128
10 Correct 4 ms 504 KB n = 128
11 Correct 4 ms 504 KB n = 128
12 Correct 5 ms 504 KB n = 128
13 Correct 4 ms 488 KB n = 128
14 Correct 5 ms 504 KB n = 128
15 Correct 4 ms 504 KB n = 128
# Verdict Execution time Memory Grader output
1 Correct 5 ms 636 KB n = 128
2 Correct 4 ms 504 KB n = 128
3 Correct 4 ms 504 KB n = 128
4 Correct 5 ms 524 KB n = 128
5 Correct 5 ms 504 KB n = 128
6 Correct 5 ms 504 KB n = 128
7 Correct 5 ms 504 KB n = 128
8 Correct 4 ms 504 KB n = 128
9 Correct 5 ms 504 KB n = 128
10 Correct 5 ms 504 KB n = 128
11 Correct 4 ms 504 KB n = 128
12 Correct 4 ms 504 KB n = 128
13 Correct 5 ms 504 KB n = 128
14 Correct 5 ms 504 KB n = 128
15 Correct 4 ms 504 KB n = 128