Artifact 8a76bc3da2574066e90caa51b2f8c173bb358207
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
static const unsigned MODVAL = 1000000007;
struct mint
{
unsigned val;
mint():val(0){}
mint(int x):val(x%MODVAL) {}
mint(unsigned x):val(x%MODVAL) {}
mint(LL x):val(x%MODVAL) {}
};
mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; }
mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
mint operator+(mint x, mint y) { return x+=y; }
mint operator-(mint x, mint y) { return x-=y; }
mint operator*(mint x, mint y) { return x*=y; }
template<typename T>
struct DP3x
{
int N1, N2, N3;
vector<T> data;
DP3x(int, int N2, int N3, const T& t = T())
: N1(2), N2(N2), N3(N3), data(N1*N2*N3, t) { assert(data.size()*sizeof(T) < (1<<28)); }
T& operator()(int i1, int i2, int i3)
{ i1&=1; return data[ ((i1*N2)+i2)*N3+i3 ]; }
void swap(DP3x& rhs)
{ data.swap(rhs.data); }
};
class WinterAndSnowmen { public:
int getNumber(int N, int M)
{
const int MAX = max(N,M);
mint total;
for(int B=10; B>=0; --B)
{
int HH = 2048>>(B+1);
DP3x<mint> dp(MAX+1, HH, 4);
dp(0,0,0) = 1;
for(int k=1; k<=MAX; ++k) {
for(int high=0; high<HH; ++high)
for(int key=0; key<4; ++key)
dp(k, high, key) = dp(k-1, high, key);
for(int high=0; high<HH; ++high)
for(int key=0; key<4; ++key) {
int kh = k>>(B+1);
int kk = (k>>B)&1;
if(k<=N)
dp(k, high^kh, key^(kk<<1)) += dp(k-1,high,key);
if(k<=M)
dp(k, high^kh, key^kk) += dp(k-1,high,key);
}
}
total += dp(MAX, 0, 1);
}
return total.val;
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, WinterAndSnowmen().getNumber(N, M));}
int main(){
CASE(0)
int N = 2;
int M = 2;
int _ = 4;
END
CASE(1)
int N = 1;
int M = 1;
int _ = 1;
END
CASE(2)
int N = 3;
int M = 5;
int _ = 74;
END
CASE(3)
int N = 7;
int M = 4;
int _ = 216;
END
CASE(4)
int N = 47;
int M = 74;
int _ = 962557390;
END
CASE(5)
int N = 2000;
int M = 2000;
int _ = -1;
END
/*
CASE(6)
int N = ;
int M = ;
int _ = ;
END
*/
}
// END CUT HERE