Submission #966694

# Submission time Handle Problem Language Result Execution time Memory
966694 2024-04-20T08:27:30 Z anango Unscrambling a Messy Bug (IOI16_messy) C++17
100 / 100
2 ms 856 KB
#include <vector>
#include <bits/stdc++.h>
using namespace std;

#include "messy.h"

vector<int> answer;
int N;
vector<string> construct_strings(vector<int> index_set) {
    //construct all strings going from all 1s except index_set 0s with one 1
    vector<char> s;
    vector<string> ans;
    for (int i=0; i<N; i++) {
        s.push_back('1');
    }
    for (auto i:index_set) {
        s[i] = '0';
    }
    for (auto i:index_set) {
        s[i] = '1';
        string x(s.begin(), s.end());
        //cout << l <<" " <<r << " " << i <<" " << x << endl;
        ans.push_back(x);
        s[i] = '0';
    }
    return ans;
}

void solve(int l, int r, vector<int> index_set) {
    // cout << "call " << l << " " << r << " " << index_set.size() << endl;
    assert(index_set.size()==(r-l+1));
    if (l==r) {
        assert(index_set.size()==1);
        answer[index_set.back()] = l;
        return;
    }
    int m=(l+r)/2;
    sort(index_set.begin(), index_set.end());
    //l to m and m+1 to r
    vector<string> test_strings = construct_strings(index_set);
    vector<int> firstind;
    vector<int> secondind;
    for (int i=0; i<r-l+1; i++) {
        //if i is there, put it into left, otherwise into right
        if (check_element(test_strings[i])) {
            firstind.push_back(index_set[i]);
        }
        else {
            secondind.push_back(index_set[i]);
        }
    }
    // cout << "split " << l <<" " << m <<" " << r << endl;
    for (auto i:firstind) {
        // cout << i <<" ";
    }
    // cout << endl;
    for (auto i:secondind) {
        // cout << i <<" ";
    }
    // cout << endl;
    solve(l, m, firstind);
    solve(m+1, r, secondind);
    return;

}

std::vector<int> restore_permutation(int n, int w, int r) {
    N=n;
    //n=8
    //10000000
    //01000000
    //00100000
    //00010000
    //from these we have 4 indices for which (0,1,2,3)->(a,b,c,d)
    //and the other 4 indices (4,5,6,7)->(e,f,g,h)
    //so now solve the problem for n=4 but putting 1 in any irrelevant bits
    //so for each subpower, say 2^c, for each blocked segment of that length,
    //replace each of that segment with 1 and the rest 0, and the rest of the bits 1, for half of such possibilities
    //then query all of them
    int b=-1;
    int on=n;
    while (on) {
        on/=2;
        b++;
    }
    answer=vector<int>(n,-1);
    for (int c = 1; c<=b; c++) {
        for (int st=0; st<n; st+=1<<c) {
            //insert the first half of the segment
            int l=st;
            int r=(st+(1<<c))-1;
            int m = (l+r)/2;
            vector<char> s;
            for (int i=0; i<l; i++) {
                s.push_back('1');
            }
            for (int i=l; i<=r; i++) {
                s.push_back('0');
            }
            for (int i=r+1; i<n; i++) {
                s.push_back('1');
            }
            for (int i=l; i<=m; i++) {
                s[i] = '1';
                string x(s.begin(), s.end());
                // cout << l <<" " <<m <<" " << r << " " << i <<" " << x << endl;
                add_element(x);
                s[i] = '0';
            }
        }
    }
    compile_set();
    vector<int> range;
    for (int i=0; i<n; i++) {
        range.push_back(i);
    }
    solve(0, n-1, range);
    return answer;
}

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 solve(int, int, std::vector<int>)':
messy.cpp:31:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |     assert(index_set.size()==(r-l+1));
      |            ~~~~~~~~~~~~~~~~^~~~~~~~~
messy.cpp:53:15: warning: unused variable 'i' [-Wunused-variable]
   53 |     for (auto i:firstind) {
      |               ^
messy.cpp:57:15: warning: unused variable 'i' [-Wunused-variable]
   57 |     for (auto i:secondind) {
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB n = 8
2 Correct 0 ms 348 KB n = 8
3 Correct 1 ms 348 KB n = 8
4 Correct 0 ms 348 KB n = 8
5 Correct 0 ms 348 KB n = 8
6 Correct 1 ms 348 KB n = 8
7 Correct 1 ms 344 KB n = 8
8 Correct 0 ms 348 KB n = 8
9 Correct 0 ms 348 KB n = 8
10 Correct 1 ms 348 KB n = 8
11 Correct 1 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 344 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB n = 32
2 Correct 0 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 1 ms 348 KB n = 32
8 Correct 0 ms 348 KB n = 32
9 Correct 1 ms 348 KB n = 32
10 Correct 0 ms 348 KB n = 32
11 Correct 1 ms 344 KB n = 32
12 Correct 1 ms 348 KB n = 32
13 Correct 0 ms 436 KB n = 32
14 Correct 1 ms 344 KB n = 32
15 Correct 1 ms 348 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n = 32
2 Correct 0 ms 348 KB n = 32
3 Correct 1 ms 348 KB n = 32
4 Correct 0 ms 348 KB n = 32
5 Correct 0 ms 348 KB n = 32
6 Correct 1 ms 348 KB n = 32
7 Correct 1 ms 500 KB n = 32
8 Correct 1 ms 348 KB n = 32
9 Correct 1 ms 348 KB n = 32
10 Correct 0 ms 348 KB n = 32
11 Correct 2 ms 600 KB n = 32
12 Correct 1 ms 348 KB n = 32
13 Correct 1 ms 856 KB n = 32
14 Correct 1 ms 344 KB n = 32
15 Correct 1 ms 348 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB n = 128
2 Correct 1 ms 604 KB n = 128
3 Correct 2 ms 600 KB n = 128
4 Correct 1 ms 604 KB n = 128
5 Correct 1 ms 604 KB n = 128
6 Correct 1 ms 604 KB n = 128
7 Correct 1 ms 604 KB n = 128
8 Correct 1 ms 604 KB n = 128
9 Correct 1 ms 600 KB n = 128
10 Correct 1 ms 600 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 600 KB n = 128
15 Correct 2 ms 604 KB n = 128
# 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 436 KB n = 128
5 Correct 1 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 1 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 428 KB n = 128
14 Correct 1 ms 600 KB n = 128
15 Correct 2 ms 604 KB n = 128