Submission #3414012
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[2005], fact_inv[2005];
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 < 2005; i++){
val *= i;
val %= mod;
fact[i] = val;
}
for(int i = 0; i < 2005; 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(12), SegTree(12)};
int main(void)
{
make_fact();
cin >> N >> K;
if(N == 1){
cout << 1 << endl;
return 0;
}
seg[0].update(0, 1);
for(int i = 1; i <= K-1; i++){
seg[i%2].init();
for(int j = 0; j <= N-1; j++){
llint tmp = 0;
tmp += seg[(i+1)%2].query(j+1, j+1);
if(N-(i+j) > 0) tmp += seg[(i+1)%2].query(j, j), tmp %= mod;
if(j <= N-1-i) tmp += seg[(i+1)%2].query(0, j-1), tmp %= mod;
seg[i%2].update(j, tmp);
}
}
llint ans = 0;
for(int i = 0; i <= N-1; i++){
ans += seg[(K-1)%2].query(i, i) * pow(2, max(N-K-1, 0LL)) % mod;
ans %= mod;
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
F - Solitaire |
User |
leaf1415 |
Language |
C++14 (GCC 5.4.1) |
Score |
1200 |
Code Size |
2119 Byte |
Status |
AC |
Exec Time |
1154 ms |
Memory |
384 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
1200 / 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 |
2 ms |
384 KB |
00_example_02.txt |
AC |
2 ms |
384 KB |
00_example_03.txt |
AC |
699 ms |
384 KB |
01.txt |
AC |
2 ms |
384 KB |
02.txt |
AC |
281 ms |
384 KB |
03.txt |
AC |
2 ms |
384 KB |
04.txt |
AC |
9 ms |
384 KB |
05.txt |
AC |
2 ms |
384 KB |
06.txt |
AC |
2 ms |
384 KB |
07.txt |
AC |
2 ms |
384 KB |
08.txt |
AC |
2 ms |
384 KB |
09.txt |
AC |
962 ms |
384 KB |
10.txt |
AC |
2 ms |
384 KB |
11.txt |
AC |
2 ms |
384 KB |
12.txt |
AC |
974 ms |
384 KB |
13.txt |
AC |
5 ms |
384 KB |
14.txt |
AC |
489 ms |
384 KB |
15.txt |
AC |
82 ms |
384 KB |
16.txt |
AC |
506 ms |
384 KB |
17.txt |
AC |
413 ms |
384 KB |
18.txt |
AC |
821 ms |
384 KB |
19.txt |
AC |
740 ms |
384 KB |
20.txt |
AC |
356 ms |
384 KB |
21.txt |
AC |
2 ms |
384 KB |
22.txt |
AC |
1154 ms |
384 KB |
23.txt |
AC |
2 ms |
384 KB |