Skip to content

Instantly share code, notes, and snippets.

@adis-io
Created November 8, 2012 15:43
Show Gist options
  • Select an option

  • Save adis-io/4039567 to your computer and use it in GitHub Desktop.

Select an option

Save adis-io/4039567 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#define Z (~0u<<30)
int main(){
int n, a, i, j, k, t;
unsigned long m[4] = {0};
scanf("%d", &n);
for(i=0; i<n; i++){
scanf("%d", &a);
for(j=1,k=0;!(a&j) && k<3;j<<=1,k++);
for(j=3;j>=0;j--){
t=j+k<3?j+k:3;
if((m[t]|m[j])&Z)
m[t]=Z;
else
m[t]+=m[j];
}
m[k]++;
}
printf(m[3]>1000000000u ? "too many eights\n" : "%d\n", m[3]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment