Submission #853680

# Submission time Handle Problem Language Result Execution time Memory
853680 2023-09-25T02:19:07 Z hngwlog Unscrambling a Messy Bug (IOI16_messy) C++14
100 / 100
2 ms 604 KB
#include <bits/stdc++.h>
#include "messy.h"
using namespace std;

#define fi first
#define se second
#define _size(x) (int)x.size()
#define BIT(i, x) ((x >> i) & 1)
#define MASK(n) ((1 << n) - 1)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define FOR(i, a, b) for (int i = a, _b = (b); i <= _b; i++)
#define FORD(i, a, b) for (int i = a, _b = (b); i >= _b; i--)
#define FORB1(i, mask) for (int i = mask; i > 0; i ^= i & - i)
#define FORB0(i, n, mask) for (int i = ((1 << n) - 1) ^ mask; i > 0; i ^= i & - i)
#define FORALL(i, a) for (auto i: a)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);

vector<int> ans;

void add(int n, vector<int> g) {

    if (_size(g) == 1) return ;
    vector<int> used(n);
    string s = "";
    REP(i, n) s += '0';
    FORALL(pos, g) s[pos] = '1';
    REP(i, _size(g) / 2) {
        used[g[i]]++;
        s[g[i]] = '0';
        add_element(s);
        s[g[i]] = '1';
    }
    vector<int> newG;
    FORALL(pos, g) if (used[pos]) newG.push_back(pos);
    add(n, newG);
    newG.clear();
    FORALL(pos, g) if (!used[pos]) newG.push_back(pos);
    add(n, newG);
}

void solve(int n, vector<int> g, vector<int> _g) {

    if (_size(g) == 1) {
        ans[_g.back()] = g.back();
        return ;
    }
    vector<int> used(n), _used(n);
    REP(i, _size(g) / 2) used[g[i]]++;
    string t = "";
    REP(i, n) t += '0';
    FORALL(pos, _g) t[pos] = '1';
    FORALL(pos, _g) {
        t[pos] = '0';
        if (check_element(t)) _used[pos]++;
        t[pos] = '1';
    }
    vector<int> newG, _newG;
    FORALL(pos, g) if (used[pos]) newG.push_back(pos);
    FORALL(pos, _g) if (_used[pos]) _newG.push_back(pos);
    solve(n, newG, _newG);
    newG.clear();
    _newG.clear();
    FORALL(pos, g) if (!used[pos]) newG.push_back(pos);
    FORALL(pos, _g) if (!_used[pos]) _newG.push_back(pos);
    solve(n, newG, _newG);
}

vector<int> restore_permutation(int n, int w, int r) {

    ans.resize(n);
    vector<int> g, _g;
    REP(i, n) g.push_back(i), _g.push_back(i);
    add(n, g);
    compile_set();
    solve(n, g, _g);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n = 8
2 Correct 0 ms 348 KB n = 8
3 Correct 0 ms 348 KB n = 8
4 Correct 0 ms 348 KB n = 8
5 Correct 0 ms 348 KB n = 8
6 Correct 0 ms 512 KB n = 8
7 Correct 0 ms 344 KB n = 8
8 Correct 0 ms 348 KB n = 8
9 Correct 0 ms 348 KB n = 8
10 Correct 0 ms 348 KB n = 8
11 Correct 0 ms 348 KB n = 8
12 Correct 0 ms 348 KB n = 8
13 Correct 0 ms 348 KB n = 8
14 Correct 0 ms 348 KB n = 8
15 Correct 0 ms 348 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n = 32
2 Correct 1 ms 348 KB n = 32
3 Correct 1 ms 348 KB n = 32
4 Correct 0 ms 348 KB n = 32
5 Correct 1 ms 348 KB n = 32
6 Correct 1 ms 348 KB n = 32
7 Correct 0 ms 348 KB n = 32
8 Correct 1 ms 344 KB n = 32
9 Correct 0 ms 348 KB n = 32
10 Correct 0 ms 348 KB n = 32
11 Correct 1 ms 344 KB n = 32
12 Correct 0 ms 348 KB n = 32
13 Correct 1 ms 548 KB n = 32
14 Correct 1 ms 348 KB n = 32
15 Correct 0 ms 348 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB n = 32
2 Correct 0 ms 348 KB n = 32
3 Correct 0 ms 348 KB n = 32
4 Correct 0 ms 348 KB n = 32
5 Correct 0 ms 348 KB n = 32
6 Correct 0 ms 348 KB n = 32
7 Correct 1 ms 348 KB n = 32
8 Correct 0 ms 348 KB n = 32
9 Correct 0 ms 348 KB n = 32
10 Correct 0 ms 348 KB n = 32
11 Correct 0 ms 348 KB n = 32
12 Correct 0 ms 444 KB n = 32
13 Correct 1 ms 348 KB n = 32
14 Correct 1 ms 344 KB n = 32
15 Correct 0 ms 348 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB n = 128
2 Correct 1 ms 604 KB n = 128
3 Correct 1 ms 604 KB n = 128
4 Correct 1 ms 604 KB n = 128
5 Correct 1 ms 604 KB n = 128
6 Correct 2 ms 604 KB n = 128
7 Correct 2 ms 604 KB n = 128
8 Correct 1 ms 600 KB n = 128
9 Correct 1 ms 604 KB n = 128
10 Correct 1 ms 432 KB n = 128
11 Correct 1 ms 604 KB n = 128
12 Correct 1 ms 604 KB n = 128
13 Correct 1 ms 600 KB n = 128
14 Correct 1 ms 600 KB n = 128
15 Correct 1 ms 604 KB n = 128
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB n = 128
2 Correct 1 ms 600 KB n = 128
3 Correct 1 ms 604 KB n = 128
4 Correct 1 ms 604 KB n = 128
5 Correct 2 ms 604 KB n = 128
6 Correct 1 ms 604 KB n = 128
7 Correct 2 ms 604 KB n = 128
8 Correct 1 ms 604 KB n = 128
9 Correct 2 ms 604 KB n = 128
10 Correct 1 ms 604 KB n = 128
11 Correct 1 ms 604 KB n = 128
12 Correct 1 ms 604 KB n = 128
13 Correct 1 ms 604 KB n = 128
14 Correct 1 ms 604 KB n = 128
15 Correct 1 ms 604 KB n = 128