KiAsaGibona's blog

By KiAsaGibona, 11 years ago, In English

Hello everyone .. Welcome to my Blog :)

Some Days ago I coded a solution of this problem .. And my code was

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<iostream>

using namespace std;

int row,col,arr[9][9],sum[9],mask[270];

int rec(int mask)
{
    int cur=__builtin_popcount(mask);
    if(cur==col)
    {
        int MAX=-9;
        int MIN=999999999;

        for(int i=0;i<row;i++)
        {
            MAX=max(MAX,sum[i]);
            MIN=min(MIN,sum[i]);
        }

        return (int) MAX-MIN;
    }

    int ans=999999999;

    for(int i=0;i<col;i++)
    {
        if( (mask & (1<<i)) == 0)
        {
            int POW=pow(10,(cur));

            for(int rr=0;rr<row;rr++)
                sum[rr]+=(POW*arr[rr][i]);

            ans=min(ans,rec(mask|(1<<i)));

            for(int rr=0;rr<row;rr++)
                sum[rr]-=(POW*arr[rr][i]);
        }
    }
    return ans;
}

int main()
{
    scanf(" %d %d",&row,&col);

    for(int i=0;i<row;i++)
        for(int j=0;j<col;j++)
        {
            char tmp;
            scanf(" %c",&tmp);
            arr[i][j]=tmp-'0';
        }

     int ans=(rec(0));
     printf("%d\n",ans);
    return 0;
}

But the funny fact is when I submitted the code if fails to pass first system test .. Then I went to other peoples Accepted codes and tried sample inputs and my code provides correct output for each and every input.. I am freaked out : ) .. And looking forward to have your's ideas about this.. Is this a surver error .. or there a GHOST sitting in CodeForces :)

Tags bug
  • Vote: I like it
  • -23
  • Vote: I do not like it

»
11 years ago, # |
  Vote: I like it +5 Vote: I do not like it

pow() works with floating point values and may return imprecise results. Try to implement a proper integer power function.

  • »
    »
    11 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Thank You sir.. I just got it ACC.. There is so much to know :)