답안 #967603

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967603 2024-04-22T13:41:05 Z MarwenElarbi Unscrambling a Messy Bug (IOI16_messy) C++17
100 / 100
2 ms 604 KB
#include<bits/stdc++.h>
using namespace std;

void add_element(std::string x);
bool check_element(std::string x);
void compile_set();

string text;
set<int> st;
void dav_add(int l,int r){
    int mid=(r+l)/2;
    if(l==r) return;
    for (int i = l; i <= mid; ++i)
    {
        text[i]='1';
        //cout <<text<<endl;
        add_element(text);
        text[i]='0';
    }
    for (int i = mid+1; i <= r ; ++i)
    {
        text[i]='1';
    }
    dav_add(l,mid);
    for (int i = mid+1; i <= r ; ++i)
    {
        text[i]='0';
    }
    for (int i = l; i <= mid; ++i)
    {
        text[i]='1';
    }
    dav_add(mid+1,r);
    for (int i = l; i <= mid; ++i)
    {
        text[i]='0';
    }
    return;
}
vector<int> res;
void dav_check(int l,int r){
    vector<int> left;
    vector<int> right;
    if(l==r){
        res[*st.begin()]=l;
        return;
    }
    for(auto u:st){
        text[u]='1';
        //cout <<u<<" ";
        if(!check_element(text)){
            right.push_back(u);
        }else {
            left.push_back(u);
            //cout <<text<<endl;
        }
        text[u]='0';
    }//cout <<endl;
    for (int i = 0; i < right.size(); ++i)
    {
        //cout <<right[i]<<" ";
        text[right[i]]='1';
        st.erase(right[i]);
    }//cout <<endl;
    int mid=(r+l)/2;
    dav_check(l,mid);
    for (int i = 0; i < right.size(); ++i)
    {
        text[right[i]]='0';
        st.insert(right[i]);
    }
    for (int i = 0; i < left.size(); ++i)
    {
        text[left[i]]='1';
        st.erase(left[i]);
    }
    dav_check(mid+1,r);
    for (int i = 0; i < left.size(); ++i)
    {
        text[left[i]]='0';
        st.insert(left[i]);
    }
    return;
}
std::vector<int> restore_permutation(int n, int w, int r) {
    text="";
    res.resize(n);
    for (int i = 0; i < n; ++i)
    {
        st.insert(i);
        text.push_back('0');
    }
    dav_add(0,n-1);
    compile_set();
    dav_check(0,n-1);
    return res;
}

Compilation message

messy.cpp: In function 'void dav_check(int, int)':
messy.cpp:59:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (int i = 0; i < right.size(); ++i)
      |                     ~~^~~~~~~~~~~~~~
messy.cpp:67:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for (int i = 0; i < right.size(); ++i)
      |                     ~~^~~~~~~~~~~~~~
messy.cpp:72:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for (int i = 0; i < left.size(); ++i)
      |                     ~~^~~~~~~~~~~~~
messy.cpp:78:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for (int i = 0; i < left.size(); ++i)
      |                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB n = 8
2 Correct 1 ms 348 KB n = 8
3 Correct 0 ms 436 KB n = 8
4 Correct 0 ms 348 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 1 ms 344 KB n = 8
10 Correct 1 ms 344 KB n = 8
11 Correct 0 ms 348 KB n = 8
12 Correct 1 ms 348 KB n = 8
13 Correct 0 ms 348 KB n = 8
14 Correct 1 ms 348 KB n = 8
15 Correct 1 ms 348 KB n = 8
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n = 32
2 Correct 0 ms 348 KB n = 32
3 Correct 0 ms 436 KB n = 32
4 Correct 1 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 348 KB n = 32
8 Correct 0 ms 348 KB n = 32
9 Correct 0 ms 348 KB n = 32
10 Correct 1 ms 348 KB n = 32
11 Correct 0 ms 348 KB n = 32
12 Correct 0 ms 348 KB n = 32
13 Correct 1 ms 600 KB n = 32
14 Correct 1 ms 344 KB n = 32
15 Correct 1 ms 348 KB n = 32
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB n = 32
2 Correct 0 ms 344 KB n = 32
3 Correct 0 ms 348 KB n = 32
4 Correct 0 ms 436 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 0 ms 348 KB n = 32
9 Correct 0 ms 348 KB n = 32
10 Correct 0 ms 348 KB n = 32
11 Correct 1 ms 348 KB n = 32
12 Correct 1 ms 344 KB n = 32
13 Correct 0 ms 348 KB n = 32
14 Correct 0 ms 436 KB n = 32
15 Correct 1 ms 348 KB n = 32
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 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 1 ms 604 KB n = 128
6 Correct 2 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 604 KB n = 128
10 Correct 1 ms 604 KB n = 128
11 Correct 1 ms 600 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
# 결과 실행 시간 메모리 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 436 KB n = 128
6 Correct 1 ms 604 KB n = 128
7 Correct 1 ms 600 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 432 KB n = 128
12 Correct 1 ms 604 KB n = 128
13 Correct 1 ms 604 KB n = 128
14 Correct 2 ms 604 KB n = 128
15 Correct 1 ms 604 KB n = 128