CodeChef submission 788957 (C++ 4.3.2) plaintext list. Status: TLE, problem LUCKY3, contest JAN12. By jfogh (jfogh), 2012-01-11 14:10:07.

#include <set> #include <cstdio> #include <vector> #include <string> #include <cstring> #include <cstdlib> #include <sstream> #include <algorithm> #include <map> #include <cmath> #include <iostream> #include <iomanip> #include <queue> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define PB push_back #define MP make_pair #define FOR(i,from,to) for (int i = from; i < to; i++) #define FORit(c,it) for (typeof(c.begin()) it=c.begin(); c.end()!=it;++it) #define SZ(v) v.size() #define LEN(s) s.length() #define X first #define Y second #define INIT(m,v) memset(m,v,sizeof(m)) #define ALL(c) c.begin(), c.end() #define V vector static ll dp[1<<19]; static int convert(int d) { int res = 0, digits = 0; for (int ii = 0; d; ++ii) { int rem = d % 10; d /= 10; int digit; if (4 > rem) digit = 0; else if (4 == rem) digit = 1; else if (7 > rem) digit = 2; else if (7 == rem) digit = 3; else return -1; res |= digit << ii * 2 + 3; digits = ii + 1; } res |= digits - 1; return res; } static int combine(int a, int b) { int res=max((a & 0x7), (b & 0x7)); int digits=res + 1; FOR(ii,0,digits) res |= max((b >> ii * 2 + 3) & 0x3, (a >> ii * 2 + 3) & 0x3) << ii * 2 + 3; return res; } static bool lucky(int n) { int digits = (n & 0x7)+1; n>>=3; FOR(ii,0,digits) if (1 != ((n >> ii * 2) & 0x3) && 3 != ((n >> ii * 2) & 0x3)) return false; return true; } int main (int argc, char **argv) { int T; FOR(tt,0,T) { int n; INIT(dp,0); dp[0]=1; FOR(ii,0,n) { int d; d = convert(d); if (-1 != d) { FOR(kk,0,1<<19) { int jj = (1<<19)-1-kk; int a = combine(d,jj); dp[a]+=dp[jj]; } } } ll res=0; FOR(ii,1,1<<19) if (lucky(ii) && dp[ii]) { res+=dp[ii]; } } return 0; }

## Comments

**Please login at the top to post a comment.**