ARRANGE - runtime error

prob: http://www.codechef.com/problems/ARRANGE

the same code below works fine and outputs what is expected at http://www.compileonline.com
however, it gives “runtime error” on both ideone, and codechef. dont know what is the problem :expressionless:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
   int a[65536][16], flag;
   for(int i=0; i<16; i++) a[0][i]=0;
   for(int i=1; i<65536; i++) {
    flag=0;
       for(int j=15; j>=0; j--) {
           if(a[i-1][j]==0 && flag==0) {
               a[i][j]=1;
               flag=1;
           }
           else if(a[i-1][j]==1 && flag==0) {
               a[i][j]=0;
           }
           else if(flag==1) {
               a[i][j]=a[i-1][j];
           }
       }
   }
   int t, k, b[65536][16], cnt, d;
   char s[65536], c[65536];
   scanf("%d", &t);
   while(t--) {
       scanf("%d%s", &k, s);
       d=pow(2, k);
       for(int i=0; i<d; i++) {
           for(int j=15, m=0; m<k; m++, j--) {
               b[i][m]=a[i][j];
           }
       }
       for(int i=0; i<d; i++) {
           for(int j=0; j<d; j++) {
               cnt=0;
               for(int m=0; m<k; m++) {
                   if(b[i][m]==a[j][16-k+m]) cnt++;
                }
               if(cnt==k) {
                   c[i]=s[j];
                   break;
               }
           }
       }
       printf("%s\n", c);
   }
   return 0;
}

googling, i came up with: [http://stackoverflow.com/a/1022596][1]

however, i dont know whether that applies to 2 or more dimensional array. if yes, next obstacle: i dont know how to call that function in my above code. in the code above array assignments are from char string s[] to c[] and from int array a[][] to b[][].
[1]: http://stackoverflow.com/a/1022596

a[][] is binary representation of numbers, b[][] is inversed version of a[][].

by the way, i peeked AC codes, saw there many bitwise operations, any help on how to carry out bitwise oper in this specific prob would be appreciated.(im familiar with XOR >> << etc)