답안 #427076

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
427076 2021-06-14T12:10:32 Z 2qbingxuan Unscrambling a Messy Bug (IOI16_messy) C++17
100 / 100
3 ms 556 KB
#include "messy.h"
#include <bits/stdc++.h>
#ifdef local
#define debug(x...) qqbx(#x, x)
#define pary(x...) danb(#x, x)
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "\e[1;32m(" << s << ") = ("), ..., (std::cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
    std::cerr << "\e[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        std::cerr << (f++ ? ", " : "") << *L;
    std::cerr << " ]\e[0m\n";
}
#else
#define debug(...) ((void)0)
#define pary(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)


using namespace std;
const int maxn = 128;

int n;
int p[maxn];
int write_cnt, read_cnt;
void dc_add(int l, int r, string s) {
    if (l+1 == r) return;
    int m = l+(r-l)/2;
    for (int i = m; i < r; i++) {
        string tmp = s;
        tmp[i] = '1';
        add_element(tmp);
        ++write_cnt;
    }
    string L = s, R = s;
    for (int i = m; i < r; i++) L[i] = '1';
    for (int i = l; i < m; i++) R[i] = '1';
    dc_add(l, m, L);
    dc_add(m, r, R);
}
void dc_check(int l, int r, string s, vector<int> candidate) {
    assert (r - l == candidate.size());
    if (l+1 == r) {
        p[l] = candidate[0];
        return;
    }
    int m = l+(r-l)/2;
    vector<int> lson, rson;
    for (int i: candidate) {
        string tmp = s;
        tmp[i] = '1';
        ++read_cnt;
        if (check_element(tmp)) {
            rson.push_back(i);
        } else {
            lson.push_back(i);
        }
    }
    string L = s, R = s;
    for (int i: rson) L[i] = '1';
    for (int i: lson) R[i] = '1';
    dc_check(l, m, L, lson);
    dc_check(m, r, R, rson);
}
vector<int> restore_permutation(int _n, int w, int r) {
    n = _n;
    string init(n, '0');
    dc_add(0, n, init);
    compile_set();
    vector<int> id(n);
    iota(all(id), 0);
    dc_check(0, n, init, id);
    debug(write_cnt, read_cnt, w, r);
    vector<int> ans(n);
    for (int i = 0; i < n; i++)
        ans[p[i]] = i;
    return ans;
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from messy.cpp:2:
messy.cpp: In function 'void dc_check(int, int, std::string, std::vector<int>)':
messy.cpp:47:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     assert (r - l == candidate.size());
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB n = 8
2 Correct 1 ms 204 KB n = 8
3 Correct 1 ms 204 KB n = 8
4 Correct 1 ms 204 KB n = 8
5 Correct 1 ms 204 KB n = 8
6 Correct 1 ms 204 KB n = 8
7 Correct 1 ms 204 KB n = 8
8 Correct 1 ms 332 KB n = 8
9 Correct 1 ms 204 KB n = 8
10 Correct 1 ms 204 KB n = 8
11 Correct 1 ms 204 KB n = 8
12 Correct 1 ms 204 KB n = 8
13 Correct 1 ms 292 KB n = 8
14 Correct 1 ms 204 KB n = 8
15 Correct 1 ms 204 KB n = 8
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB n = 32
2 Correct 1 ms 204 KB n = 32
3 Correct 1 ms 288 KB n = 32
4 Correct 1 ms 204 KB n = 32
5 Correct 1 ms 204 KB n = 32
6 Correct 1 ms 204 KB n = 32
7 Correct 1 ms 204 KB n = 32
8 Correct 1 ms 204 KB n = 32
9 Correct 1 ms 204 KB n = 32
10 Correct 1 ms 292 KB n = 32
11 Correct 1 ms 204 KB n = 32
12 Correct 1 ms 256 KB n = 32
13 Correct 1 ms 204 KB n = 32
14 Correct 1 ms 292 KB n = 32
15 Correct 1 ms 204 KB n = 32
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB n = 32
2 Correct 1 ms 204 KB n = 32
3 Correct 1 ms 204 KB n = 32
4 Correct 1 ms 204 KB n = 32
5 Correct 1 ms 296 KB n = 32
6 Correct 1 ms 204 KB n = 32
7 Correct 1 ms 300 KB n = 32
8 Correct 1 ms 204 KB n = 32
9 Correct 1 ms 204 KB n = 32
10 Correct 1 ms 204 KB n = 32
11 Correct 1 ms 204 KB n = 32
12 Correct 1 ms 204 KB n = 32
13 Correct 1 ms 204 KB n = 32
14 Correct 1 ms 204 KB n = 32
15 Correct 1 ms 292 KB n = 32
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB n = 128
2 Correct 2 ms 460 KB n = 128
3 Correct 2 ms 492 KB n = 128
4 Correct 2 ms 460 KB n = 128
5 Correct 3 ms 416 KB n = 128
6 Correct 2 ms 460 KB n = 128
7 Correct 2 ms 460 KB n = 128
8 Correct 2 ms 556 KB n = 128
9 Correct 2 ms 460 KB n = 128
10 Correct 2 ms 460 KB n = 128
11 Correct 2 ms 460 KB n = 128
12 Correct 2 ms 460 KB n = 128
13 Correct 2 ms 460 KB n = 128
14 Correct 2 ms 460 KB n = 128
15 Correct 2 ms 460 KB n = 128
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 460 KB n = 128
2 Correct 2 ms 460 KB n = 128
3 Correct 2 ms 460 KB n = 128
4 Correct 2 ms 460 KB n = 128
5 Correct 2 ms 460 KB n = 128
6 Correct 2 ms 424 KB n = 128
7 Correct 2 ms 460 KB n = 128
8 Correct 3 ms 460 KB n = 128
9 Correct 2 ms 420 KB n = 128
10 Correct 2 ms 460 KB n = 128
11 Correct 2 ms 460 KB n = 128
12 Correct 2 ms 460 KB n = 128
13 Correct 2 ms 460 KB n = 128
14 Correct 2 ms 460 KB n = 128
15 Correct 2 ms 420 KB n = 128