Submission #1076267

# Submission time Handle Problem Language Result Execution time Memory
1076267 2024-08-26T12:24:07 Z clementine Unscrambling a Messy Bug (IOI16_messy) C++17
100 / 100
3 ms 856 KB
#include <vector>
using namespace std;
#include "messy.h"
#include<bits/stdc++.h>

int ans[130];
vector<string> subsets;

void createSubsets(int l, int r, int n)
{
    if(l != r)
    {
        int mid = (l + r) /2;
        string s(n, '1');
        for(int i = l; i <=r; i ++)
        {
            s[i] = '0';
        }
        for(int i = l; i <=mid; i ++)
        {
            string a = s;
            a[i] = '1';
            subsets.push_back(a);
            add_element(a);
        }
        createSubsets(l, mid, n);
        createSubsets(mid + 1, r, n);
    }
}

void query(int l, int r, int n, vector<int> ones)
{
    /*
    cout << l << " and " << r <<"\nones: ";
    for(auto val: ones)
    {
        cout << val << " ";
    }cout << '\n';
    */
    if(l == r)
    {
       for(int i= 0; i <n; i ++)
       {
            bool inones = false;
            for(int j = 0; j <ones.size(); j ++)
            {
                if(ones[j] == i)
                {
                    inones = true;
                }
            }
            if(!inones)
            {
                //cout << l << "corresponds to " << i << '\n';
                ans[i] = l;
                return;
            }
       }
    }
    int mid = (l + r) / 2;
    vector<int> futurelefts, futurerights;
    string s(n, '0');
    for(auto idx: ones)
    {
        s[idx] = '1';
    }
    for(int i = 0; i <n; i ++)
    {
        if(s[i] == '0')
        {
            string a = s;
            a[i] = '1';
            if(check_element(a))
            {   //cout << a << " checnekd \n";
                futurerights.push_back(i);
            }
            else 
            {
            futurelefts.push_back(i);
            //cout << a << " notchecked \n";
            }
        }
    }
    for(auto val:ones)
    {
        futurelefts.push_back(val);
        futurerights.push_back(val);
    }
    query(l, mid, n, futurelefts);
    query(mid + 1, r, n, futurerights);
    
}

vector<int> restore_permutation(int n, int w, int r) {
    createSubsets(0, n-1, n );
    compile_set();
    /*
    for(string s : subsets)
    {
        cout << s << '\n';
    }
    cout << '\n';*/
    vector<int> a;
    query(0, n-1, n, a);
    vector<int> ret;
    for(int i = 0; i <n; i ++)
    {
        ret.push_back(ans[i]);
    }
    return ret;
}

Compilation message

messy.cpp: In function 'void query(int, int, int, std::vector<int>)':
messy.cpp:45:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |             for(int j = 0; j <ones.size(); j ++)
      |                            ~~^~~~~~~~~~~~
# 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 604 KB n = 8
5 Correct 0 ms 348 KB n = 8
6 Correct 0 ms 348 KB n = 8
7 Correct 0 ms 348 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 1 ms 344 KB n = 8
12 Correct 0 ms 348 KB n = 8
13 Correct 1 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 1 ms 600 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 344 KB n = 32
6 Correct 0 ms 348 KB n = 32
7 Correct 0 ms 356 KB n = 32
8 Correct 0 ms 348 KB n = 32
9 Correct 0 ms 344 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 348 KB n = 32
14 Correct 1 ms 348 KB n = 32
15 Correct 0 ms 344 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n = 32
2 Correct 1 ms 348 KB n = 32
3 Correct 1 ms 344 KB n = 32
4 Correct 1 ms 348 KB n = 32
5 Correct 0 ms 348 KB n = 32
6 Correct 0 ms 348 KB n = 32
7 Correct 0 ms 432 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 0 ms 348 KB n = 32
12 Correct 0 ms 432 KB n = 32
13 Correct 1 ms 348 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 2 ms 600 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 600 KB n = 128
6 Correct 1 ms 604 KB n = 128
7 Correct 2 ms 604 KB n = 128
8 Correct 2 ms 604 KB n = 128
9 Correct 1 ms 604 KB n = 128
10 Correct 2 ms 604 KB n = 128
11 Correct 1 ms 604 KB n = 128
12 Correct 2 ms 600 KB n = 128
13 Correct 3 ms 604 KB n = 128
14 Correct 1 ms 604 KB n = 128
15 Correct 1 ms 604 KB n = 128
# Verdict Execution time Memory Grader output
1 Correct 2 ms 856 KB n = 128
2 Correct 1 ms 604 KB n = 128
3 Correct 2 ms 600 KB n = 128
4 Correct 2 ms 604 KB n = 128
5 Correct 1 ms 604 KB n = 128
6 Correct 1 ms 600 KB n = 128
7 Correct 1 ms 604 KB n = 128
8 Correct 2 ms 604 KB n = 128
9 Correct 1 ms 604 KB n = 128
10 Correct 1 ms 604 KB n = 128
11 Correct 2 ms 600 KB n = 128
12 Correct 1 ms 604 KB n = 128
13 Correct 2 ms 604 KB n = 128
14 Correct 1 ms 604 KB n = 128
15 Correct 1 ms 604 KB n = 128