Submission #2528756


Source Code Expand

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
#include <sys/time.h>
#include <fstream>
#include <iomanip>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define REP(i,n)  FOR(i,0,n)
#define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;
#define sz(s) (int)((s).size())


#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))

double pi=3.14159265358979323846;

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
	os << "[ ";
	REP(i,z.size())os << z[i] << ", " ;
	return ( os << "]" << endl);
}

template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
	os << "set( ";
	EACH(p,z)os << (*p) << ", " ;
	return ( os << ")" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
	os << "{ ";
	EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ;
	return ( os << "}" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){
	return ( os << "(" << z.first << ", " << z.second << ",)" );
}

double get_time(){
	struct timeval tv;
	gettimeofday(&tv, NULL);
	return tv.tv_sec + tv.tv_usec*1e-6;
}

typedef unsigned int uint32_t;
struct RND{
	uint32_t x;
	uint32_t y;
	uint32_t z;
	uint32_t w;
	RND(){
		x=123456789;
		y=362436069;
		z=521288629;
		w=88675123;
	}
	void init(int seed){
		x=123456789;
		y=362436069;
		z=521288629;
		w=seed+100;
		REP(i,10)get();
	}
	uint32_t get(){
		uint32_t t;
		t=x^(x<<11);
		x=y;y=z;z=w;
		w=(w^(w>>19))^(t^(t>>8));
		return w;
	}
};
RND rnd;

ll double_to_ll(double d){
	if(d>0)return d+0.5;
	return d-0.5;
}

ll mod=1000000007;
struct mint{
	ll value;
	mint():value(0){}
	mint(ll v):value((v%mod+mod)%mod){}
};
mint& operator+=(mint&a, mint b){return a=a.value+b.value;}
mint& operator-=(mint&a, mint b){return a=a.value-b.value;}
mint& operator*=(mint&a, mint b){return a=a.value*b.value;}
mint operator+(mint a, mint b){return a+=b;}
mint operator-(mint a, mint b){return a-=b;}
mint operator*(mint a, mint b){return a*=b;}
mint operator-(mint a){return 0-a;}
bool operator==(mint a, mint b){return a.value==b.value;}
bool operator!=(mint a, mint b){return a.value!=b.value;}


std::ostream& operator<<(std::ostream& os, const mint& m){
return ( os << m.value );}
ll extgcd(ll a, ll b, ll &x, ll &y){
	ll d=a;
	if(b!=0){
		d=extgcd(b, a%b, y, x);
		y-=(a/b)*x;
	}
	else{
		x=1,y=0;
	}
	return d;
}
ll modinverse(ll a, ll b){
	ll x,y;
	ll d=extgcd(a,b, x, y);
	assert(d==1);
	return (x%b+b)%b;
}
mint& operator/=(mint&a, mint b){return a=a.value*modinverse(b.value,mod);}
mint operator/(mint a, mint b){return a/=b;}

const int D=2000010;
mint factorial[D];
mint invfactorial[D];
mint pow2[D];

struct Precomp{
	Precomp(){
		factorial[0]=1;
		for(ll k=1; k<D; k++)factorial[k].value = factorial[k-1].value*k%mod;
		invfactorial[D-1] = mint(1) / factorial[D-1];
		for(ll k=D-2; k>=0; k--) invfactorial[k].value = invfactorial[k+1].value*(k+1)%mod;
		pow2[0]=1;
		for(ll k=1; k<D; k++)pow2[k].value = pow2[k-1].value*2%mod;

	}
}precomp;

mint comb(ll n, ll a){
	if(0<=a && a<=n)return factorial[n] * invfactorial[a] * invfactorial[n-a];
	else return mint(0);
}

mint Rcomb(ll n, ll r){
	// x_1+...+x_r= nの個数
	if(n==0 && r>=0)return 1;
	return comb(n+r-1, r-1);
}


ll memo[2010][2010];

mint rec(int n, int i){
	assert(0<=i && i<n);
	 ll &ret = memo[n][i];
	if(ret != -1) return mint(ret);
	mint ans;
	if(n==1 || n==2){
		ans = 1;
	}
	else if(i==0){
		ans = 2*rec(n-1, 0);
	}
	else if(i==n-1 || i==n-2){
		ans = comb(2*(n-1),n-1) / n ;
	}
	else{
		ans = rec(n-1, i)*2 + rec(n,i-1)/2;
	}
	return ret = ans.value;
}

void _main(istream &inp){
	nclr(memo);
	ll n,k;
	inp >> n >> k;
	cout << rec(n,k-1) << endl;
//	FOR(n,17,18){
//		rep(i,n){
//			deb(n);deb(i);deb(rec(n,i));debl;
//		}
//	}
//	cout << fixed << setprecision(12);
//	while(true){
//		break;
//	}

}

int main(){
	if(0){
		ifstream ifs("test.txt");
		_main(ifs);
	}
	else{
		_main(cin);
	}
	return 0;
}

Submission Info

Submission Time
Task F - Solitaire
User hirosegolf
Language C++14 (GCC 5.4.1)
Score 1200
Code Size 5298 Byte
Status AC
Exec Time 554 ms
Memory 78976 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1200 / 1200
Status
AC × 3
AC × 26
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 110 ms 78720 KB
00_example_02.txt AC 110 ms 78720 KB
00_example_03.txt AC 483 ms 78848 KB
01.txt AC 110 ms 78720 KB
02.txt AC 244 ms 78848 KB
03.txt AC 110 ms 78720 KB
04.txt AC 113 ms 78720 KB
05.txt AC 110 ms 78720 KB
06.txt AC 110 ms 78720 KB
07.txt AC 110 ms 78720 KB
08.txt AC 110 ms 78720 KB
09.txt AC 554 ms 78976 KB
10.txt AC 110 ms 78720 KB
11.txt AC 110 ms 78720 KB
12.txt AC 543 ms 78976 KB
13.txt AC 111 ms 78720 KB
14.txt AC 385 ms 78848 KB
15.txt AC 145 ms 78720 KB
16.txt AC 392 ms 78848 KB
17.txt AC 343 ms 78848 KB
18.txt AC 535 ms 78976 KB
19.txt AC 504 ms 78976 KB
20.txt AC 314 ms 78848 KB
21.txt AC 110 ms 78720 KB
22.txt AC 110 ms 78720 KB
23.txt AC 110 ms 78848 KB