Artifact Content
Not logged in

Artifact 244c2d068d085457b322ecc642e87b6596f6b786


#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 <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

static const int MODVAL = 1000000009;
struct mint
{
	int val;
	mint():val(0){}
	mint(int x):val(x%MODVAL) {}
	mint(LL  x):val(x%MODVAL) {}
};

mint operator+(mint x, mint y) { return x.val+y.val; }
mint operator-(mint x, mint y) { return x.val-y.val+MODVAL; }
mint operator*(mint x, mint y) { return LL(x.val)*y.val; }
mint POW(mint x, int e) {
	mint v = 1;
	for(;e;x=x*x,e>>=1)
		if(e&1)
			v=v*x;
	return v;
}
mint operator/(mint x, mint y) { return x * POW(y, MODVAL-2); }

vector<mint> FAC_(1,1);
void FAC_INIT(int n) { for(int i=1; i<=n; ++i) FAC_.push_back( FAC_.back()*i ); }
mint FAC(mint x)       { return FAC_[x.val]; }
mint C(mint n, mint k) { return k.val<0 || n.val<k.val ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }

class Passwords { public:
	int countValid(int N, int L, int U, int D) 
	{
		FAC_INIT(200000);

		//  Sigma_{D<=d<=N-U-L} [C(N,d) 10^d Sigma_{L<=l,U<=u,u+l=N-d}[ C(N-d,u) 26^u 26^l ] ]
		//= Sigma_{D<=d<=N-U-L} [C(N,d) 10^d 26^(N-d) Sigma_{U<=u<=N-d-L}[ C(N-d,u) ] ]
		//   let f(N') = Sigma_{U<=u<=N'-L}[ C(N',u) ]
		//      then by Pascal's triangle, f(N') = 2*f(N'-1)+C(N'-1,U-1)+C(N'-1,N'-L)

		mint answer=0, f=C(U+L,U);
		for(int d=N-U-L; d>=D; --d)
		{
			answer = answer + C(N,d)*POW(10,d)*POW(26,N-d)*f;
			f = f*2 + C(N-d,U-1) + C(N-d, N-d-L+1);
		}
		return answer.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(_, Passwords().countValid(N, L, U, D));}
int main(){

CASE(0)
	int N = 2; 
	int L = 0; 
	int U = 0; 
	int D = 2; 
	int _ = 100; 
END
CASE(1)
	int N = 3; 
	int L = 1; 
	int U = 1; 
	int D = 1; 
	int _ = 40560; 
END
CASE(2)
	int N = 4; 
	int L = 1; 
	int U = 1; 
	int D = 1; 
	int _ = 5029440; 
END
CASE(3)
	int N = 10; 
	int L = 1; 
	int U = 3; 
	int D = 3; 
	int _ = 818019214; 
END
CASE(4)
	int N = 5; 
	int L = 2; 
	int U = 2; 
	int D = 2; 
	int _ = 0; 
END
CASE(5)
	int N = 199201;
	int L = 0; 
	int U = 70000; 
	int D = 0; 
	int _ = 943311211; 
END
CASE(6)
	int N = 200000; 
	int L = 11; 
	int U = 111; 
	int D = 1111; 
	int _ = 298235838; 
END
}
// END CUT HERE