Wednesday, April 2, 2014

codechef DAILY - Daily Train solution

codechef DAILY - Daily Train: http://www.codechef.com/problems/DAILY

codechef DAILY - Daily Train editorial: http://discuss.codechef.com/questions/4010/daily-editorial

codechef DAILY - Daily Train solution: http://ideone.com/UKGPUu


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

int main() {
int x, n, a[10], cnt, f[10];
char s[60];
f[0]=1;
for(int i=1; i<7; i++) f[i]=f[i-1]*i;
cnt=0;
scanf("%d%d", &x, &n);
while(n--) {
for(int i=0; i<10; i++) a[i]=0;
scanf("%s", s);
for(int i=0; i<54; i++) {
if(s[i]=='0') {
if(i<36) a[i/4]++;
else a[8-(i-36)/2]++;
}
}
for(int i=0; i<9; i++) if(a[i]>=x) cnt+=f[a[i]]/f[x]/f[a[i]-x];
}
printf("%d", cnt);
return 0;
}

note: dont forget to use loop while assigning 0 to array a[] (array that keeps track of empty places at every compartment). dont use memset(a, 0, sizeof(a)), it gave runtime error signal:8 (sigfpe) on my code and it cost me hours to realize that bug.

No comments:

Post a Comment