Submission #412850

# Submission time Handle Problem Language Result Execution time Memory
412850 2021-05-27T17:02:37 Z MasterTaster Unscrambling a Messy Bug (IOI16_messy) C++14
20 / 100
1 ms 296 KB
#include <bits/stdc++.h>
#include "messy.h"

#define pb push_back
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second

using namespace std;

vector<int> p;

int xNady(int x, int y)
{
    if (y==0) return 1;
    int ret=1;
    for (int i=x; i>x-y; i--) ret*=i;
    for (int i=y; i>0; i--) ret/=i;
    return ret;
}

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

    if (n==8)
    {
        for (int i=0; i<7; i++)
        {
            for (int mask=0; mask<(1<<8); mask++)
            {
                if (__builtin_popcount(mask)!=i+1) continue;
                if (mask&(1<<i)) continue;
                string s="00000000";
                for (int j=0; j<8; j++) if (mask&(1<<j)) s[j]='1'; else s[j]='0';
                add_element(s);
                ///cout<<"dodajem "<<s<<endl;
            }
        }

        ///cout<<endl<<"kad obrnes:"<<endl;
        compile_set();
        ///cout<<endl;

        int kolko[10];
        for (int i=0; i<7; i++)
        {
            for (int j=0; j<8; j++) kolko[j]=0;
            for (int mask=0; mask<(1<<8); mask++)
            {
                if (__builtin_popcount(mask)!=i+1) continue;

                string s="00000000";
                for (int j=0; j<8; j++) if (mask&(1<<j)) s[j]='1'; else s[j]='0';
                bool dal=check_element(s);
                if (!dal) continue;

                ///cout<<s<<endl;

                for (int j=0; j<8; j++) if (mask&(1<<j)) kolko[j]++;

                if (mask&(1<<i))
                {
                    int drugi=-1;
                    mask++;
                    for (; mask<(1<<8); mask++)
                    {
                        if (__builtin_popcount(mask)!=i+1) continue;

                        string s="00000000";
                        for (int j=0; j<8; j++) if (mask&(1<<j)) s[j]='1'; else s[j]='0';
                        bool dal=check_element(s);
                        if (!dal) continue;

                        for (int j=0; j<8; j++) if (mask&(1<<j)) kolko[j]++;
                    }

                    for (int j=0; j<8; j++)
                    {
                        if (j==i) continue;
                        ///cout<<j<<" j kolko[j] "<<kolko[j]<<endl;
                        if (kolko[j]!=xNady(6, i)) { drugi=j; break; }
                    }
                    //cout<<i<<" "<<drugi<<endl;

                    for (int j=0; j<8; j++)
                    {
                        if (j!=i && j!=drugi) p.pb(j);
                        else if (j==i) p.pb(drugi);
                        else p.pb(i);
                    }
                    return p;
                }
            }
        }

        for (int i=0; i<8; i++) p.pb(i);
        return p;
    }

    /*add_element("0");
    compile_set();
    check_element("0");
    return std::vector<int>();*/
}
/*
8 256 256
0 1 2 6 4 5 3 7
*/

Compilation message

messy.cpp: In function 'std::vector<int> restore_permutation(int, int, int)':
messy.cpp:104:1: warning: control reaches end of non-void function [-Wreturn-type]
  104 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n = 8
2 Correct 1 ms 204 KB n = 8
3 Correct 1 ms 204 KB n = 8
4 Correct 1 ms 204 KB n = 8
5 Correct 1 ms 204 KB n = 8
6 Correct 1 ms 204 KB n = 8
7 Correct 1 ms 204 KB n = 8
8 Correct 1 ms 204 KB n = 8
9 Correct 1 ms 204 KB n = 8
10 Correct 1 ms 204 KB n = 8
11 Correct 1 ms 204 KB n = 8
12 Correct 1 ms 204 KB n = 8
13 Correct 1 ms 204 KB n = 8
14 Correct 1 ms 296 KB n = 8
15 Correct 1 ms 204 KB n = 8
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB grader returned WA
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB grader returned WA
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB grader returned WA
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB grader returned WA
2 Halted 0 ms 0 KB -