Submission #827093
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>
#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 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=4100000;
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);
}
mint a[2010][2010];
void _main(istream &inp){
ll N,K;
inp >> N >>K;
if(N==1 || K==1){
cout << 1 << endl;
return;
}
clr(a);
a[0][0]=1;
for(ll m=1; m<N; m++){
mint su = 0;
for(ll i=0; i<=m; i++){
su += a[m-1][i];
a[m][i] = Rcomb(K-2, m*(K-1)+i+1) * su;
}
}
mint res = 0;
rep(i,N) res += a[N-1][i];
res = res * factorial[N];
cout << res.value << endl;
while(true){
break;
}
}
int main(){
if(0){
ifstream ifs("test.txt");
_main(ifs);
}
else{
_main(cin);
}
return 0;
}
Submission Info
Submission Time |
|
Task |
F - Leftmost Ball |
User |
hirosegolf |
Language |
C++14 (GCC 5.4.1) |
Score |
1600 |
Code Size |
5005 Byte |
Status |
AC |
Exec Time |
874 ms |
Memory |
127872 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
1600 / 1600 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt |
All |
0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt |
Case Name |
Status |
Exec Time |
Memory |
0_00.txt |
AC |
530 ms |
127872 KB |
0_01.txt |
AC |
519 ms |
127872 KB |
0_02.txt |
AC |
503 ms |
127872 KB |
0_03.txt |
AC |
874 ms |
127872 KB |
1_00.txt |
AC |
498 ms |
127872 KB |
1_01.txt |
AC |
499 ms |
127872 KB |
1_02.txt |
AC |
498 ms |
127872 KB |
1_03.txt |
AC |
865 ms |
127872 KB |
1_04.txt |
AC |
852 ms |
127872 KB |
1_05.txt |
AC |
871 ms |
127872 KB |
1_06.txt |
AC |
855 ms |
127872 KB |
1_07.txt |
AC |
861 ms |
127872 KB |
1_08.txt |
AC |
838 ms |
127872 KB |
1_09.txt |
AC |
840 ms |
127872 KB |
1_10.txt |
AC |
839 ms |
127872 KB |
1_11.txt |
AC |
855 ms |
127872 KB |
1_12.txt |
AC |
531 ms |
127872 KB |
1_13.txt |
AC |
792 ms |
127872 KB |
1_14.txt |
AC |
513 ms |
127872 KB |
1_15.txt |
AC |
600 ms |
127872 KB |
1_16.txt |
AC |
660 ms |
127872 KB |
1_17.txt |
AC |
823 ms |
127872 KB |
1_18.txt |
AC |
514 ms |
127872 KB |
1_19.txt |
AC |
858 ms |
127872 KB |