Submission #3402085
Source Code Expand
#include <iostream>
#include <vector>
#define llint long long
#define mod 1000000007
using namespace std;
struct SegTree{
int size;
vector<llint> seg;
SegTree(){}
SegTree(int size){
this->size = size;
seg.resize(1<<(size+1));
}
void init()
{
for(int i = 0; i < (1<<(size+1)); i++) seg[i] = 0;
}
void update(int i, llint val)
{
i += (1 << size);
seg[i] = val;
while(i > 1){
i /= 2;
seg[i] = (seg[i*2]+seg[i*2+1]) % mod;
}
}
llint query(int a, int b, int k, int l, int r)
{
if(b < l || r < a) return 0;
if(a <= l && r <= b) return seg[k];
llint lval = query(a, b, k*2, l, (l+r)/2);
llint rval = query(a, b, k*2+1, (l+r)/2+1, r);
return (lval+rval)%mod;
}
llint query(int a, int b)
{
if(a > b) return 0;
return query(a, b, 1, 0, (1<<size)-1);
}
};
llint fact[100005], fact_inv[100005];
llint pow(llint a, llint n)
{
if(n == 0) return 1;
if(n % 2){
return ((a%mod) * (pow(a, n-1)%mod)) % mod;
}
else{
return pow((a*a)%mod, n/2) % mod;
}
}
void make_fact()
{
llint val = 1;
fact[0] = 1;
for(int i = 1; i < 100005; i++){
val *= i;
val %= mod;
fact[i] = val;
}
for(int i = 0; i < 100005; i++){
fact_inv[i] = pow(fact[i], mod-2);
}
}
llint comb(llint n, llint k)
{
llint ret = 1;
ret *= fact[n];
ret *= fact_inv[k], ret %= mod;
ret *= fact_inv[n-k], ret %= mod;
return ret;
}
llint N, K;
SegTree seg[2] = {SegTree(17), SegTree(17)};
int main(void)
{
make_fact();
cin >> N >> K;
seg[0].update(0, 1);
for(int i = 1; i <= K-1; i++){
seg[i%2].init();
for(int j = 0; j <= K-1; j++){
llint tmp = 0;
tmp += seg[(i+1)%2].query(j+1, j+1);
if(K-(i+j) > 0) tmp += seg[(i+1)%2].query(j, j), tmp %= mod;
if(j <= K-1-i) tmp += seg[(i+1)%2].query(0, j-1), tmp %= mod;
seg[i%2].update(j, tmp);
//cout << tmp << " ";
}
//cout << endl;
}
llint ans = seg[(K-1)%2].query(0, 0);
ans *= comb(N-1, K-1), ans %= mod;
ans *= pow(2, max(N-K-1, 0LL)), ans %= mod;
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
F - Solitaire |
User |
leaf1415 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2105 Byte |
Status |
WA |
Exec Time |
1912 ms |
Memory |
7936 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 1200 |
Status |
|
|
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 |
40 ms |
5888 KB |
00_example_02.txt |
AC |
40 ms |
5888 KB |
00_example_03.txt |
WA |
555 ms |
5888 KB |
01.txt |
WA |
41 ms |
5888 KB |
02.txt |
WA |
418 ms |
5888 KB |
03.txt |
AC |
45 ms |
5888 KB |
04.txt |
WA |
58 ms |
5888 KB |
05.txt |
AC |
40 ms |
5888 KB |
06.txt |
AC |
40 ms |
5888 KB |
07.txt |
WA |
41 ms |
5888 KB |
08.txt |
WA |
43 ms |
5888 KB |
09.txt |
WA |
1368 ms |
7936 KB |
10.txt |
WA |
41 ms |
5888 KB |
11.txt |
AC |
42 ms |
5888 KB |
12.txt |
WA |
1541 ms |
5888 KB |
13.txt |
WA |
47 ms |
5888 KB |
14.txt |
WA |
294 ms |
5888 KB |
15.txt |
WA |
188 ms |
5888 KB |
16.txt |
WA |
306 ms |
5888 KB |
17.txt |
WA |
220 ms |
5888 KB |
18.txt |
WA |
783 ms |
5888 KB |
19.txt |
WA |
624 ms |
5888 KB |
20.txt |
WA |
178 ms |
5888 KB |
21.txt |
AC |
40 ms |
5888 KB |
22.txt |
AC |
1912 ms |
5888 KB |
23.txt |
AC |
40 ms |
5888 KB |