Submission #711687

# Submission time Handle Problem Language Result Execution time Memory
711687 2023-03-17T11:11:13 Z TimDee Unscrambling a Messy Bug (IOI16_messy) C++17
100 / 100
3 ms 600 KB
#include "messy.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)

map<string,int> scuza;
int ask(string&s) {
    if (scuza[s]) return scuza[s]-1;
    int x=check_element(s);
    scuza[s]=x+1;
    return x;
}

void rec(int l, int r, string&s) {
    if (r-l==1) return;
    int m=(l+r)>>1;
    for (int i=l; i<m; ++i) {
        s[i]='1';
        add_element(s);
        s[i]='0';
    }
    for(int i=m;i<r;++i) {
        s[i]='1';
    }
    rec(l,m,s);
    for(int i=l;i<m;++i) {
        s[i]='1';
    }
    for(int i=m;i<r;++i) {
        s[i]='0';
    }
    rec(m,r,s);
    for(int i=l;i<m;++i) {
        s[i]='0';
    }
}
vector<int> ans;
int N;
void rec(int l, int r, vector<int>&v) {
    string z(N,'0');
    for(auto&x:v) z[x]='1';
    if (r-l==1) {
        forn(i,N) if (z[i]=='0') {
            ans[i]=l;
            return;
        }
    }
    int m=(l+r)>>1;
    vector<int> f,s;
    //cout<<l<<' '<<r<<' '<<z<<'\n';
    forn(j,N) {
        if (z[j]=='1') continue;
        z[j]='1';
        int x=ask(z);
        z[j]='0';
        if (x) f.push_back(j);
        else s.push_back(j);
    }
    for(auto&x:s) v.push_back(x);
    rec(l,m,v);
    for(auto&x:s) v.pop_back();
    for(auto&x:f) v.push_back(x);
    rec(m,r,v);
    for(auto&x:f) v.pop_back();

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

    string z(n,'0');
    rec(0,n,z);
    ans.assign(n,-1); N=n;
    compile_set();
    vector<int> v;
    rec(0,n,v);
    return ans;

}

Compilation message

messy.cpp: In function 'void rec(int, int, std::vector<int>&)':
messy.cpp:61:14: warning: unused variable 'x' [-Wunused-variable]
   61 |     for(auto&x:s) v.pop_back();
      |              ^
messy.cpp:64:14: warning: unused variable 'x' [-Wunused-variable]
   64 |     for(auto&x:f) v.pop_back();
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 8
2 Correct 1 ms 216 KB n = 8
3 Correct 1 ms 212 KB n = 8
4 Correct 1 ms 212 KB n = 8
5 Correct 1 ms 212 KB n = 8
6 Correct 1 ms 212 KB n = 8
7 Correct 1 ms 212 KB n = 8
8 Correct 1 ms 212 KB n = 8
9 Correct 1 ms 212 KB n = 8
10 Correct 1 ms 212 KB n = 8
11 Correct 1 ms 212 KB n = 8
12 Correct 1 ms 292 KB n = 8
13 Correct 1 ms 212 KB n = 8
14 Correct 1 ms 212 KB n = 8
15 Correct 1 ms 212 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 32
2 Correct 1 ms 212 KB n = 32
3 Correct 1 ms 212 KB n = 32
4 Correct 1 ms 212 KB n = 32
5 Correct 1 ms 212 KB n = 32
6 Correct 1 ms 212 KB n = 32
7 Correct 1 ms 212 KB n = 32
8 Correct 1 ms 212 KB n = 32
9 Correct 1 ms 296 KB n = 32
10 Correct 1 ms 296 KB n = 32
11 Correct 1 ms 340 KB n = 32
12 Correct 1 ms 296 KB n = 32
13 Correct 1 ms 212 KB n = 32
14 Correct 1 ms 212 KB n = 32
15 Correct 1 ms 296 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 32
2 Correct 1 ms 300 KB n = 32
3 Correct 1 ms 212 KB n = 32
4 Correct 1 ms 292 KB n = 32
5 Correct 1 ms 212 KB n = 32
6 Correct 1 ms 212 KB n = 32
7 Correct 1 ms 340 KB n = 32
8 Correct 1 ms 340 KB n = 32
9 Correct 1 ms 212 KB n = 32
10 Correct 1 ms 300 KB n = 32
11 Correct 1 ms 212 KB n = 32
12 Correct 1 ms 212 KB n = 32
13 Correct 1 ms 212 KB n = 32
14 Correct 1 ms 304 KB n = 32
15 Correct 1 ms 340 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 2 ms 556 KB n = 128
2 Correct 2 ms 596 KB n = 128
3 Correct 2 ms 552 KB n = 128
4 Correct 2 ms 552 KB n = 128
5 Correct 2 ms 552 KB n = 128
6 Correct 2 ms 596 KB n = 128
7 Correct 2 ms 596 KB n = 128
8 Correct 2 ms 480 KB n = 128
9 Correct 2 ms 596 KB n = 128
10 Correct 2 ms 596 KB n = 128
11 Correct 2 ms 596 KB n = 128
12 Correct 2 ms 596 KB n = 128
13 Correct 2 ms 556 KB n = 128
14 Correct 2 ms 596 KB n = 128
15 Correct 2 ms 596 KB n = 128
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB n = 128
2 Correct 2 ms 596 KB n = 128
3 Correct 2 ms 596 KB n = 128
4 Correct 2 ms 596 KB n = 128
5 Correct 2 ms 596 KB n = 128
6 Correct 3 ms 596 KB n = 128
7 Correct 2 ms 556 KB n = 128
8 Correct 2 ms 596 KB n = 128
9 Correct 2 ms 596 KB n = 128
10 Correct 2 ms 596 KB n = 128
11 Correct 2 ms 556 KB n = 128
12 Correct 2 ms 596 KB n = 128
13 Correct 3 ms 556 KB n = 128
14 Correct 2 ms 596 KB n = 128
15 Correct 2 ms 600 KB n = 128