Problem:
Problem D:
Goofy Converter
Nathan O. Davis is a student at the department of integrated systems. He is now taking a class in in-
tegrated curcuits. He is an idiot. One day, he got an assignment as follows: design a logic circuit that
takes a sequence of positive integers as input, and that outputs a sequence of 1-bit integers from which
the original input sequence can be restored uniquely.
Nathan has no idea. So he searched for hints on the Internet, and found several pages that describe the
1-bit DAC. This is a type of digital-analog converter which takes a sequence of positive integers as input,
and outputs a sequence of 1-bit integers.
Seeing how 1-bit DAC works on these pages, Nathan came up with a new idea for the desired converter.
His converter takes a sequence L of positive integers, and a positive integer
M
aside from the sequence,
and outputs a sequence
K
of 1-bit integers such that:
He is not so smart, however. It is clear that his converter does not work for some sequences. Your task is
to write a program in order to show the new converter cannot satisfy the requirements of his assignment,
even though it would make Nathan in despair.
Input
The input consists of a series of data sets. Each data set is given in the following format:
N M
L
0
L
1
. . .
L
N
-1
N
is the length of the sequence
L
.
M
and
L
are the input to Nathan’s converter as described above. You
may assume the followings: 1 ≤
N
≤ 1000, 1 ≤
M
≤ 12, and 0 ≤
L
j
≤
M
for
j
= 0, . . . ,
N
- 1.
The input is terminated by
N
=
M
= 0.
Output
For each data set, output a binary sequence
K
of the length (
N
+
M
- 1) if there exists a sequence which
holds the equation mentioned above, or “Goofy” (without quotes) otherwise. If more than one sequence
is possible, output any one of them.
Sample Input
4 4
4 3 2 2
4 4
4 3 2 3
0 0
Output for the Sample Input
1111001
Goofy

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll s(ll n){
    ll sum = 0;
    for(int i = 0; (1 << i) <= n; i++){
        sum += ((1 << i) | n) == n;
    }
    return sum;
}
int main() {
    ll n,m;
    while(cin >> n >> m){
        if (n == m && n == 0){
            break;
        }
        vector<ll> a(n);
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        ll mask = 1 << m;
        vector<vector<bool>> dp(n + 1,vector<bool>(mask,false));
        vector<vector<int>> pred(n + 1,vector<int>(mask));
        for(int i = 0; i < mask;i++){
            dp[0][i] = true;
        }

        for(int i = 1; i <= n; i++){
            for(int j = 0; j < mask;j++){
                if(s(j) == a[i-1] && (dp[i-1][j % (1 << (m-1)) * 2])){
                    dp[i][j] = true;
                    pred[i][j] = 0;
                } if(s(j) == a[i-1] && dp[i-1][j % (1 << (m-1)) * 2 + 1]){
                    dp[i][j] = true;
                    pred[i][j] = 1;
                }
            }
        }
        ll ans = -1;
        for(int i = 0; i < mask; i++){
            if(dp[n][i]){
                ans = i;
            }
        }
        if(ans == -1){
            cout << "Goofy\n";
            continue;
        }
        string s = "";
        for(int i = 0; i < m; i++){
           s += to_string(int(((1 << i) | ans) == ans));
        }
        for(int i = n - 1; i > 0; i--){
            s = to_string(pred[i + 1][ans]) + s;
            ans = (ans % (1 << (m-1))) * 2 + pred[i + 1][ans];
        }
        cout << s << '\n';
    }
}
accuracy: 1
time_ms: 2210
memory_kb: 19728
final_rank: 20

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)
#define Endl endl
#define all(a) a.begin(), a.end()
#define pr(i, j) make_pair(i, j)
#define isin(x, l, r) (l <= x && x < r)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define srt(ar) sort(ar.begin(), ar.end())
#define rev(ar) reverse(ar.begin(), ar.end())
#define jge(f, s, t) cout << (f ? s : t) << endl
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define printar(ar)             \
    do                          \
    {                           \
        for (auto dbg : ar)     \
        {                       \
            cout << dbg << " "; \
        }                       \
        cout << endl;           \
    } while (0)
const ll inf = 1e18;
const ld pi = 3.14159265358979;
const ld eps = 1e-9;
template <class T, ll n, ll idx = 0>
auto make_vec(const ll (&d)[n], const T &init) noexcept
{
    if constexpr (idx < n)
        return std::vector(d[idx], make_vec<T, n, idx + 1>(d, init));
    else
        return init;
}

template <class T, ll n>
auto make_vec(const ll (&d)[n]) noexcept
{
    return make_vec(d, T{});
}
//////////////// 以下を貼る ////////////////
template <class T>
size_t HashCombine(const size_t seed, const T &v)
{
    return seed ^ (std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
/* pair用 */
template <class T, class S>
struct std::hash<std::pair<T, S>>
{
    size_t operator()(const std::pair<T, S> &keyval) const noexcept
    {
        return HashCombine(std::hash<T>()(keyval.first), keyval.second);
    }
};
////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while (true)
    {
        ll n, m;
        cin >> n >> m;
        if (n == 0)
        {
            break;
        }
        vector<ll> l(n);
        rep(i, 0, n)
        {
            cin >> l[i];
        }
        rep(i, 0, (1LL << m))
        {
            vector<ll> ar;
            ll cnt = 0;
            rep(j, 0, m)
            {
                if (i >> j & 1)
                {
                    ar.push_back(1);
                    cnt++;
                }
                else
                {
                    ar.push_back(0);
                }
            }
            if (cnt != l[0])
            {
                continue;
            }
            bool f = true;
            rep(j, m, n + m - 1)
            {
                if (ar[j - m] == 0)
                {
                    if (l[j - m] - l[j - m + 1] == 0)
                    {
                        ar.push_back(0);
                    }
                    else if (l[j - m] - l[j - m + 1] == -1)
                    {
                        ar.push_back(1);
                    }
                    else
                    {
                        f = false;
                        break;
                    }
                }
                else
                {
                    if (l[j - m] - l[j - m + 1] == 0)
                    {
                        ar.push_back(1);
                    }
                    else if (l[j - m] - l[j - m + 1] == 1)
                    {
                        ar.push_back(0);
                    }
                    else
                    {
                        f = false;
                        break;
                    }
                }
            }
            if (f)
            {
                rep(j, 0, ar.size())
                {
                    cout << ar[j];
                }
                cout << endl;
                goto next;
            }
        }
        cout << "Goofy" << endl;
    next:;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3584
final_rank: 7

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int pop[1<<12];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    for (int i = 0; i < (1<<12); ++i) {
        pop[i] = __builtin_popcount(i);
    }
    int n,m;
    while (cin >> n >> m, n+m) {
        vector<int> l(n);
        for (int i = 0; i < n; ++i) {
            cin >> l[i];
        }
        vector<vector<bool>> dp(n, vector<bool>(1<<m));
        vector<vector<int>> pre(n, vector<int>(1<<m));
        for (int i = 0; i < (1<<m); ++i) {
            if (pop[i] == l[0]) dp[0][i] = true;
        }
        for (int i = 0; i + 1 < n; ++i) {
            for (int j = 0; j < (1<<m); ++j) {
                if (!dp[i][j]) continue;
                int k = pop[j] - (j&1);
                if (k == l[i+1]) {
                    dp[i+1][j/2] = true;
                    pre[i+1][j/2] = j;
                } else if (k+1 == l[i+1]) {
                    dp[i+1][j/2 + (1<<(m-1))] = true;
                    pre[i+1][j/2 + (1<<(m-1))] = j;
                }
            }
        }
        int ok = -1;
        for (int i = 0; i < (1<<m); ++i) {
            if (dp[n-1][i]) {
                ok = i;
            }
        }
        if (ok == -1) {
            cout << "Goofy" << "\n";
        } else {
            string res;
            for (int i = (m-1); i >= 0; --i) {
                if ((1<<i)&ok) res += "1";
                else res += "0";
            }
            for (int i = n-1; i > 0; --i) {
                ok = pre[i][ok];
                if (ok&1) res += "1";
                else res += "0";
            }
            reverse(res.begin(), res.end());
            cout << res << "\n";
        }
    }
}
accuracy: 1
time_ms: 230
memory_kb: 19828
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,m;
  while(cin>>n>>m,n||m){
    int l[n];
    for(int i=0;i<n;i++) cin>>l[i];
    bool flg=0;
    for(int i=0;i<(1<<m);i++){
      int tmp=__builtin_popcountll(i);
      if(tmp!=l[0]) continue;
      string s;
      for(int j=0;j<m;j++) s.push_back('0'+((i>>j)&1));
      bool ok=1;
      for(int j=1;j<n;j++){
	tmp-=(s[j-1]=='1');
	if(tmp==l[j]) s.push_back('0');
	else if(tmp==l[j]-1) s.push_back('1'),tmp++;
	else{
	  ok=0;
	  break;
	}
      }
      if(ok){
	cout<<s<<endl;
	flg=1;
	break;
      }
    }
    if(!flg) cout<<"Goofy"<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3156
final_rank: 6

code_snippet: #include <iostream>
#include <vector>

std::vector<int> L(1000);

int N,M;
int main(void){
    while(std::cin >> N >> M){
        if(N == 0 && M == 0) break;
        for(int i=0; i<N; ++i){
            std::cin >> L[i];
        }

        bool f;
        std::vector<int> b(1012);
        for(int S=0; S<(1<<M); ++S){
            int sum = 0;
            for(int i=0; i<M; ++i){
                b[i] = (S>>i&1);
                sum += b[i];
            }

            for(int i=0; i<N-1; ++i){
                b[M+i] = L[i+1] - L[i] + b[i];
            }

            f = (sum == L[0]);
            for(int i=0; i<N+M-1; ++i){
                if(b[i] != 0 && b[i] != 1){
                    f = false;
                }
            }
            if(f){
                break;
            }
        }

        if(f){
            for(int i=0; i<N+M-1; ++i){
                std::cout << b[i];
            }
            std::cout << std::endl;
        }else{
            std::cout << "Goofy" << std::endl;
        }
    }
}
accuracy: 1
time_ms: 90
memory_kb: 3028
final_rank: 11

code_snippet: #include <iostream>
#include <vector>

std::vector<int> L(1000);

int N,M;
int main(void){
    while(std::cin >> N >> M){
        if(N == 0 && M == 0) break;
        for(int i=0; i<N; ++i){
            std::cin >> L[i];
        }

        bool f;
        std::vector<int> b(1012);
        for(int S=0; S<(1<<M); ++S){
            int sum = 0;
            for(int i=0; i<M; ++i){
                sum += b[i] = (S>>i&1);
            }
            for(int i=0; i<N-1; ++i){
                b[M+i] = L[i+1] - L[i] + b[i];
            }

            f = (sum == L[0]);
            for(int i=0; i<N+M-1; ++i){
                if(b[i] != 0 && b[i] != 1){
                    f = false;
                }
            }
            if(f){
                break;
            }
        }

        if(f){
            for(int i=0; i<N+M-1; ++i){
                std::cout << b[i];
            }
            std::cout << std::endl;
        }else{
            std::cout << "Goofy" << std::endl;
        }
    }
}
accuracy: 1
time_ms: 90
memory_kb: 3108
final_rank: 13

code_snippet: #include<cstdio>
 
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
int main(){
    for(int n,m;scanf("%d%d",&n,&m),n;){
        int a[1000];
        rep(i,n) scanf("%d",a+i);
 
        bool ok;
        int b[1012];
        rep(S,1<<m){
            int sum=0;
            rep(i,m) sum+=b[i]=S>>i&1;
            rep(i,n-1) b[m+i]=a[i+1]-a[i]+b[i];
 
            ok=(sum==a[0]);
            rep(i,n+m-1) if(b[i]!=0 && b[i]!=1) ok=false;
            if(ok) break;
        }
 
        if(ok){ rep(i,n+m-1) printf("%d",b[i]); puts(""); } else puts("Goofy");
    }
 
    return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 2584
final_rank: 14

code_snippet: #include<bits/stdc++.h>

using namespace std;

int main(){
  int n,m;
  while(cin>>n>>m,n){
    int l[1000];
    bool ans[1100];
    for(int i=0;i<n;i++)cin>>l[i];
    bool f=1;
    for(int i=0;f&&i<1<<m;i++){
      int tmp=i;
      if(__builtin_popcount(tmp)!=l[0])continue;
      f=0;
      for(int j=0;j<m;j++)
	ans[j]=(i>>(m-j-1))%2;
      for(int j=1;j<n;j++){
	tmp=(tmp<<1)%(1<<m);
	if(__builtin_popcount(tmp)==l[j])ans[m+j-1]=0;
	else if(__builtin_popcount(tmp)+1==l[j])ans[m+j-1]=1,tmp+=1;
	else f=1;
	}
    }
    if(f)cout<<"Goofy";
    else for(int i=0;i<n+m-1;i++)cout<<ans[i];
    cout<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3100
final_rank: 12

code_snippet: #include <bits/stdc++.h>

using namespace std;

string d2b(int x, int M)
{
    string s;
    while (x > 0) {
        s += (x % 2 == 0 ? "0" : "1");
        x /= 2;
    }
    while ((int)s.size() < M) {
        s += "0";
    }
    reverse(s.begin(), s.end());
    return s;
}

int main()
{
    int N, M;
    while (cin >> N >> M, N) {
        vector<int> L(N);
        for (int i = 0; i < N; i++) {
            cin >> L[i];
        }

        vector<string> bits;
        for (int i = 0; i < (1<<M); i++) {
            if (L[0] == __builtin_popcount(i)) {
                bits.push_back(d2b(i, M));
            }
        }
        
        for (int i = 1; i < N; i++) {
            vector<string> nbits;
            for (int j = 0; j < (int)bits.size(); j++) {
                int cnt = 0;
                for (int k = i; k < i + M; k++) {
                    if (bits[j][k] == '1') {
                        cnt++;
                    }
                }
                int bit_cnt = L[i];
                if (cnt == bit_cnt) {
                    nbits.push_back(bits[j] + "0");
                } else if (cnt + 1 == bit_cnt) {
                    nbits.push_back(bits[j] + "1");
                }
            }
            bits = nbits;
        }

        if (bits.size() == 0) {
            cout << "Goofy" << endl;
        } else {
            cout << bits[0] << endl;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3272
final_rank: 8

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

int main() {
  int N, M;
  while(cin >> N >> M && (N || M)) {
    vector<int> L(N);
    rep(i, N) cin >> L[i];
    bool ok = 0;
    rep(m, 1<<M) {
      if(__builtin_popcount(m) != L[0]) continue;
      string temp;
      int count = L[0];
      rep(k, M)
        temp.push_back('0' + (m >> k & 1));
      bool ng = 0;
      REP(k, 1, N) {
        count -= temp[k-1] == '1';
        if(L[k] == count) temp.push_back('0');
        else if(L[k] == count + 1) temp.push_back('1'), count ++;
        else {
          ng = 1;
          break;
        }
      }
      if(ng) continue;
      cout << temp << endl;
      ok = 1;
      break;
    }
    if(!ok) cout << "Goofy" << endl;
  }
  
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3048
final_rank: 4

code_snippet: #include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

void dfs(vector<int>& v) {

}

int main() {

  int N, M;
  while(cin >> N >> M && (N || M)) {
    vector<int> L(N);
    rep(i, N) cin >> L[i];
    bool ok = 0;
    rep(m, 1<<M) {
      if(__builtin_popcount(m) != L[0]) continue;
      string temp;
      int count = L[0];
      rep(k, M)
        temp.push_back('0' + (m >> k & 1));
      bool ng = 0;
      REP(k, 1, N) {
        count -= temp[k-1] == '1';
        if(L[k] == count) {
          temp.push_back('0');
        } else if(L[k] == count + 1) {
          temp.push_back('1');
          count ++;
        } else {
          ng = 1;
          break;
        }
      }
      if(ng) continue;
      cout << temp << endl;
      ok = 1;
      break;
    }
    if(!ok) {
      cout << "Goofy" << endl;
    }
  }
  
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3060
final_rank: 5

code_snippet: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_M = 12;
const int MAX_LEN = MAX_N + MAX_M - 1;

/* typedef */

/* global variables */

int n, m, len, mbits;
int ls[MAX_N], ks[MAX_LEN];

/* subroutines */

bool check_ls(int bits) {
  int c = 0;
  for (int i = 0; i < m; i++, bits >>= 1)
    if ((ks[i] = bits & 1)) c++;
  if (ls[0] != c) return false;

  for (int j = 1; j < n; j++) {
    if (ks[j - 1]) c--;
    if (ls[j] == c) ks[j + m - 1] = 0;
    else if (ls[j] == c + 1) ks[j + m - 1] = 1, c++;
    else return false;
  }
  return true;
}

/* main */

int main() {
  for (;;) {
    cin >> n >> m;
    if (n == 0) break;

    for (int i = 0; i < n; i++) cin >> ls[i];

    len = n + m - 1;
    mbits = (1 << m) - 1;
    bool found = false;
    
    for (int bits = 0; ! found && bits <= mbits; bits++)
      found = check_ls(bits);

    if (found) {
      for (int i = 0; i < len; i++) cout << ks[i];
      cout << endl;
    }
    else
      cout << "Goofy" << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1168
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
  for(int N, M; cin >> N >> M && (N|M); ) {
    vector<int> L(N);
    for(int i = 0; i < N; ++i) {
      cin >> L[i];
    }
    vector<int> ans;
    for(int b = 0; b < (1<<M); ++b) {
      if(__builtin_popcount(b) != L[0]) continue;
      try {
        vector<int> v;
        for(int j = 0; j < M; ++j) v.push_back(b >> j & 1);
        int p = b;
        for(int i = 1; i < N; ++i) {
          int now = L[i-1] - (p & 1);
          int k = 0;
          if(now == L[i] || now + 1 == L[i]) {
            k = L[i] - now;
          } else {
            throw 0;
          }
          v.push_back(k);
          p = (p | (k << M)) >> 1;
        }
        ans = v;
        break;
      } catch(...) {}
    }
    if(ans.size()) {
      for(int i = 0; i < ans.size(); ++i)
        cout << ans[i];
      cout << endl;
    } else {
      cout << "Goofy" << endl;
    }
  }
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 1296
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  while(cin >> n >> m && n) {
    int a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    vector<int> b(m);
    for(int i=0; i<m; i++) {
      if(i<a[0]) b[i]=1;
      else b[i]=0;
    }
    sort(b.begin(),b.end());
    bool ok=0;
    do{
      int cnt=a[0];
      string s="";
      for(int i=0; i<m; i++) {
    if(b[i]) s+='1';
    else s+='0';
      }
      bool ck=1;
      for(int i=1; i<n; i++) {
    if(s[i-1]=='1') cnt--;
    if(cnt<a[i]) {
      s+='1';
      cnt++;
    } else s+='0';
    if(cnt!=a[i]) ck=0;
      }
      if(ck) {
    ok=1;
    cout << s << endl;
    break;
      }
    } while(next_permutation(b.begin(),b.end()));
    if(!ok) cout << "Goofy" << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 1224
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;

const int MAXN = 1010;
const int MAXM = 13;
int N, M;
int L[MAXN];
int dp[MAXN][1<<MAXM], prevj[MAXN][1<<MAXM];

int main() {
  while(cin >> N >> M && (N|M)) {
    for(int i = 0; i < N; ++i) {
      cin >> L[i];
    }
    memset(dp, 0, sizeof(dp));
    for(int j = 0; j < (1<<M); ++j) {
      dp[1][j] = (__builtin_popcount(j) == L[0]);
    }
    for(int i = 1; i < N; ++i) {
      for(int j = 0; j < (1<<M); ++j) {
	if(dp[i][j] == 0) continue;
	for(int k = 0; k < 2; ++k) {
	  int nj = (j | (k << M)) >> 1;
	  if(__builtin_popcount(nj) != L[i]) continue;
	  dp[i+1][nj] = min(2, dp[i+1][nj] + dp[i][j]);
	  prevj[i+1][nj] = j;
	}
      }
    }
    int b = -1;
    for(int j = 0; j < (1<<M); ++j) {
      if(dp[N][j]) b = j;
    }
    if(b != -1) {
      vector<int> v;
      int i, j;
      for(i = N, j = b; i > 1; --i) {
	int nj = prevj[i][j];
	v.push_back(j >> (M-1) & 1);
	j = nj;
      }
      for(int k = M-1; k >= 0; --k) {
	v.push_back(j >> k & 1);
      }
      reverse(v.begin(), v.end());
      for(int k = 0; k < v.size(); ++k) {
	cout << v[k];
      }
      cout << endl;
    } else {
      cout << "Goofy" << endl;
    }
  }
  return 0;
}
accuracy: 1
time_ms: 360
memory_kb: 65084
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
  int n,m;
  while(cin >> n >> m && n) {
    int a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    vector<int> b(m);
    for(int i=0; i<m; i++) {
      if(i<a[0]) b[i]=1;
      else b[i]=0;
    }
    sort(b.begin(),b.end());
    bool ok=0;
    do{
      int cnt=a[0];
      string s="";
      for(int i=0; i<m; i++) {
	if(b[i]) s+='1';
	else s+='0';
      }
      bool ck=1;
      for(int i=1; i<n; i++) {
	if(s[i-1]=='1') cnt--;
	if(cnt<a[i]) {
	  s+='1';
	  cnt++;
	} else s+='0';
	if(cnt!=a[i]) ck=0;
      }
      if(ck) {
	ok=1;
	cout << s << endl;
	break;
      }
    } while(next_permutation(b.begin(),b.end()));
    if(!ok) cout << "Goofy" << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 1224
final_rank: 9

code_snippet: #include<iostream>
using namespace std;
int N,M;
int L[1000];
int ans[2000];
 
bool solve(){
   
  for(int i=0;i<(1<<M);i++){
    int sum=0;
    bool flg=true;
    for(int j=0;j<M;j++){
      ans[j] = (i>>j) & 1;
      sum+=ans[j];
    }
    if(sum!=L[0])continue;
 
    for(int j=M;j<N+M-1;j++){
      sum-=ans[j-M];
      if(sum==L[j-M+1])ans[j]=0;
      else if(sum+1==L[j-M+1])ans[j]=1;
      else flg= false;
      sum+=ans[j];
    }
    if(flg)return true;
  }
  return false;
}
 
int main(){
  while(1){
    cin>>N>>M;
    if(N==0&&M==0)break;
    for(int i=0;i<N;i++)cin>>L[i];
 
    if(solve()){
      for(int j=0;j<N+M-1;j++)cout<<ans[j];
      cout<<endl;
    }else{
      cout<<"Goofy"<<endl;
    }
  }
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 1172
final_rank: 2

code_snippet: #include<stdio.h>
#include<algorithm>
using namespace std;
int dp[1100][1<<12];
int rev[1100][1<<12];
int c[1500];
int out[1500];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)scanf("%d",c+i);
		for(int i=0;i<=a;i++)for(int j=0;j<(1<<b);j++)
			dp[i][j]=0;
		for(int i=0;i<(1<<b);i++){
			if(__builtin_popcount(i)==c[0]){
				dp[1][i]=1;
			}
		}
		for(int i=1;i<a;i++){
			for(int j=0;j<(1<<b);j++){
				if(!dp[i][j])continue;
				int to=j/2;
				int tmp=__builtin_popcount(to);
				if(tmp<c[i]-1)continue;
				if(tmp>c[i])continue;
				if(tmp==c[i]){
					if(!dp[i+1][to]){
						dp[i+1][to]=1;
						rev[i+1][to]=j%2;
					}
				}else{
					if(!dp[i+1][to+(1<<(b-1))]){
						dp[i+1][to+(1<<(b-1))]=1;
						rev[i+1][to+(1<<(b-1))]=j%2;
					}
				}
			}
		}
		bool yet=true;
		for(int i=0;i<(1<<b);i++){
			if(dp[a][i]){
				yet=false;
				int ind=0;
				for(int j=b-1;j>=0;j--){
					if(i&(1<<j))out[ind++]=1;
					else out[ind++]=0;
				}
				int at=(i*2+rev[a][i])%(1<<b);
				for(int j=a-1;j>0;j--){
					out[ind++]=at%2;
					at=(at*2+rev[j][at])%(1<<b);
				}
				for(int j=ind-1;j>=0;j--)printf("%d",out[j]);
				printf("\n");
				break;
			}
		}
		if(yet)printf("Goofy\n");
	}
}
accuracy: 1
time_ms: 140
memory_kb: 35832
final_rank: 17

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

int sigma(int j,int block_length,int bits[1001]){
  int res = 0;
  for(int i = j; i < j+block_length-1;i++){
    res += bits[i];
  }
  return res;
}

string bit2str(int bits,int len){
  string res = "";
  for(int i=len-1;i>=0;i--){
    res.push_back((bits & (1<<i) ? '1' : '0'));
  }
  return res;
}

string conv_log(const vector<string>& log){
  string res = "";
  for(int i=0;i<log.size()-1;i++){
    res.push_back(log[i][0]);
  }
  res += log[log.size()-1];
  return res;
}

int next[1001][1<<12];

int main(){
  int sequence_length;
  int block_length;
  while(~scanf("%d %d",&sequence_length,&block_length)){
    if(sequence_length == 0 && block_length == 0) break;
    
    int sequence[1001];
    for(int seq_i=0; seq_i < sequence_length; seq_i++){
      scanf("%d",&sequence[seq_i]);
    }

    memset(next,-1,sizeof(next));
    for(int pos = (sequence_length + block_length - 1) - block_length; pos - 1 >= 0; pos--){
      for(int S = 0; S < (1<<block_length); S++){
        if(sequence[pos] == __builtin_popcount(S)){
          int inherit = S >> 1;

          for(int header = 0; header <= 1; header++){
            int prev = inherit | (header<<(block_length-1));
            if(sequence[pos-1] == __builtin_popcount(prev)){
              next[pos-1][prev] = S;
            }
          }
        }
      }
    }

    bool has_ans = false;
    for(int S = 0; S < (1<<block_length); S++){
      if(next[0][S] == -1) continue;
      bool isok = true;
      vector<string> log;
      int bit = S;
      for(int pos = 0; pos < sequence_length; pos++){
        log.push_back(bit2str(bit,block_length));
        if(bit == -1){
          isok = false;
          break;
        }
        bit = next[pos][bit];
      }
      
      if(isok){
        cout << conv_log(log) << endl;
        has_ans = true;
        break;
      }
    }

    if(!has_ans){
      printf("Goofy\n");
    }
  }
}
accuracy: 1
time_ms: 1400
memory_kb: 17332
final_rank: 18

code_snippet: #include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

short dp[1<<12][1025],L[1000],bc[1<<12];
int N,M;

int main(){
  rep(i,(1<<12)) bc[i] = __builtin_popcount(i);
  while( cin >> N >> M, N|M ){
    rep(i,N) cin >> L[i];
    reverse(L,L+N);
    int limit = (1<<M);
    rep(i,limit) rep(j,N+M+5) dp[i][j] = -1;        // invalid
    rep(i,limit) if( bc[i] == L[0] ) dp[i][0] = -2; // terminator

    rep(i,N-1){
      rep(j,limit){
        if( dp[j][i] == -1 ) continue;
        int bitmask = (j<<1) & ((1<<M)-1);
        int target = ( (j>>(M-1)) & 1 );
        rep(k,2){
          int nbitmask = bitmask | k;
          if( bc[nbitmask] == L[i+1] ) dp[nbitmask][i+1] = target;
        }
      }
    }

    string ans = "";
    int bitmask = -1;
    rep(i,limit) if( dp[i][N-1] != -1 ){
      bitmask = i;
      rep(j,M) {
        if( (i>>j) & 1 ) ans += "1";
        else             ans += "0";
      }
      break;
    }
    if( bitmask == -1 ) {
      puts("Goofy");
      continue;
    }
    for(int i=N-1;i>=1;i--){
      int v = dp[bitmask][i];
      ans += string(1,(char)('0'+v));
      assert( v == 0 || v == 1);
      int tmp = bitmask;
      bitmask  >>= 1;
      bitmask |= (v<<(M-1));
      bitmask &= ((1<<M)-1);
      assert( bc[bitmask] == L[i-1] );
    }
    cout << ans << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 9420
final_rank: 15