Submission #173591

# Submission time Handle Problem Language Result Execution time Memory
173591 2020-01-04T16:48:21 Z mosiashvililuka "The Lyuboyn" code (IZhO19_lyuboyn) C++14
19 / 100
776 ms 36328 KB
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,n,k,t,p[(1<<19)],pi;
map <string, int> m[29];
vector <string> v[29];
string ss;
bool bo[(1<<19)];
bool bi;
string totwo(int q){
    string s;
    while(q>0){
        if(q%2==0) s.push_back('0'); else s.push_back('1');
        q/=2;
    }
    while(s.size()<n) s.push_back('0');
    for(int h=0; h<s.size()/2; h++) swap(s[h],s[s.size()-h-1]);
    return s;
}
void dfsk(int q){
    pi++;
    p[pi]=q;
    bo[q]=1;
    if(pi==(1<<n)){
        cout<<(1<<n)<<endl;
        for(int h=1; h<=pi; h++) cout<<totwo(p[h])<<endl;
        exit(0);
    }
    for(int h=0; h<=(1<<n)-1; h++){
        if(bo[h]==0&&__builtin_popcount((p[pi]^h))==k){
            if(pi==(1<<n)-1&&__builtin_popcount((p[1]^h))!=k&&t==1) continue;
            dfsk(h);
        }
    }
    bo[q]=0;
    pi--;
}
void dfs(int q){
    pi++;
    p[pi]=q;
    bo[q]=1;
    if(pi==(1<<4)){
        bi=1;
        return;
    }
    for(int h=0; h<=(1<<4)-1; h++){
        if(bo[h]==0&&__builtin_popcount((p[pi]^h))==k){
            if(pi==(1<<4)-1&&__builtin_popcount((p[1]^h))!=k&&t==1) continue;
            dfs(h);
            if(bi==1) return;
        }
    }
    bo[q]=0;
    pi--;
}
void prnt(int q){
    cout<<v[q].size()<<endl;
    for(int h=0; h<v[q].size(); h++) cout<<v[q][h]<<endl;
    exit(0);
}
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>n>>k>>t;
    cin>>ss;
    if(n==4&&k==3&&t==1){
        dfsk(0);
    }
    if(k%2==0){
        cout<<-1;
        return 0;
    }
    if(k==1){
        v[2].push_back("00");
        v[2].push_back("01");
        v[2].push_back("11");
        v[2].push_back("10");
        if(n==2){
            prnt(n);
        }
        for(int h=3; h<=n; h++){
            for(int j=0; j<v[h-1].size(); j++){
                string zx;
                zx="0"+v[h-1][j];
                v[h].push_back(zx);
            }
            for(int j=v[h-1].size()-1; j>=0; j--){
                string zx;
                zx="1"+v[h-1][j];
                v[h].push_back(zx);
            }
        }
        prnt(n);
    }
    if(k==3){
        pi=0;
        dfs(0);
        for(int h=1; h<=pi; h++){
//            cout<<totwo(p[h])<<endl;
            m[4][totwo(p[h])]=h-1;
            v[4].push_back(totwo(p[h]));
        }
        if(n==4){
            prnt(n);
        }
//        cout<<endl;
//        cout<<pi<<" "<<v[4].size()<<endl;
        for(int h=5; h<=n; h++){
//            if(h==6) cout<<"fdsf"<<endl;
            string zx;
            for(int j=0; j<v[h-1].size(); j++){
                zx=v[h-1][j];
  //              cout<<zx<<endl;
                v[h].push_back(zx);
            }
//            return 0;
            //cout<<endl<<endl;
            //cout<<zx<<endl;
            for(int j=n-h+1; j<n-h+k; j++) if(zx[j]=='0') zx[j]='1'; else zx[j]='0';
  //          zx.erase(0,1);
            int j=m[h-1][zx];
//            cout<<zx<<endl;
  //          cout<<j<<endl;
            for(int i=j; i<v[h-1].size(); i++){
                zx=v[h-1][i];
                zx[n-h]='1';
  //              cout<<zx<<endl;
                v[h].push_back(zx);
            }
            for(int i=0; i<j; i++){
                zx=v[h-1][i];
                zx[n-h]='1';
    //            cout<<zx<<endl;
                v[h].push_back(zx);
            }
            for(int i=0; i<v[h].size(); i++) m[h][v[h][i]]=i;
        }
      //  cout<<endl<<endl<<endl<<endl<<endl;
//      cout<<v[5].size()<<endl<<v[6].size()<<endl;
        prnt(n);
    }
    return 0;
}

Compilation message

lyuboyn.cpp: In function 'std::__cxx11::string totwo(int)':
lyuboyn.cpp:15:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(s.size()<n) s.push_back('0');
           ~~~~~~~~^~
lyuboyn.cpp:16:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int h=0; h<s.size()/2; h++) swap(s[h],s[s.size()-h-1]);
                  ~^~~~~~~~~~~
lyuboyn.cpp: In function 'void prnt(int)':
lyuboyn.cpp:57:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int h=0; h<v[q].size(); h++) cout<<v[q][h]<<endl;
                  ~^~~~~~~~~~~~
lyuboyn.cpp: In function 'int main()':
lyuboyn.cpp:80:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=0; j<v[h-1].size(); j++){
                          ~^~~~~~~~~~~~~~
lyuboyn.cpp:109:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=0; j<v[h-1].size(); j++){
                          ~^~~~~~~~~~~~~~
lyuboyn.cpp:122:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int i=j; i<v[h-1].size(); i++){
                          ~^~~~~~~~~~~~~~
lyuboyn.cpp:134:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int i=0; i<v[h].size(); i++) m[h][v[h][i]]=i;
                          ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB First number in answer is not x 1 0
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 2 ms 376 KB Ok
7 Correct 2 ms 376 KB Ok
8 Correct 2 ms 380 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 776 ms 36328 KB Ok
2 Correct 387 ms 17268 KB Ok
3 Correct 5 ms 504 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 376 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Ok
2 Incorrect 31 ms 2296 KB Fail, not exactly k bits are different: line = 212
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 776 ms 36328 KB Ok
2 Correct 387 ms 17268 KB Ok
3 Correct 5 ms 504 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 2 ms 376 KB Ok
7 Incorrect 31 ms 2296 KB Fail, not exactly k bits are different: line = 212
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -