Submission #1293461


Source Code Expand

#include <cstdio>
typedef long long int64;
static const int MAXN = 2003;
static const int MODULUS = 1e9 + 7;
#define _  %  MODULUS
#define __ %= MODULUS
 
int binom[MAXN * 2][MAXN * 2] = {{ 0 }};
inline void preprocess_binomials()
{
    binom[0][0] = 1;
    for (int i = 1; i < MAXN * 2; ++i) {
        binom[i][0] = 1;
        for (int j = 1; j <= i; ++j)
            binom[i][j] = (binom[i - 1][j - 1] + binom[i - 1][j])_;
    }
}
inline int fpow(int64 base, int exp)
{
    int64 ans = 1;
    for (; exp; exp >>= 1, (base *= base)__) if (exp & 1) (ans *= base)__;
    return ans;
}
inline int catalan(int n) { return (int64)binom[2 * n][n] * fpow(n + 1, MODULUS - 2)_; }
 
int n, k;
// f[# of total elements][# of red elements] - nnumber of ways to distribute to two sides
int f[MAXN * 2][MAXN * 2] = {{ 0 }};
 
inline void preprocess_transitions()
{
    f[0][0] = 1;
    for (int i = 0; i < MAXN * 2 - 1; ++i) {
        f[i + 1][0] = f[i][0];
        for (int j = 1; j <= i + 1; ++j)
            f[i + 1][j] = (f[i + 1][j - 1] + f[i][j])_;
    }
}
 
int main()
{
    preprocess_binomials();
    scanf("%d%d", &n, &k);
    if (n == k) { printf("%d\n", catalan(n - 1)); return 0; }
 
    preprocess_transitions();
    int64 ans = 0;
    for (int m = n - k + 1; m <= n; ++m) {
        int akai = n - m, aoi = m - 1 - (n - k);
        int64 inc = f[akai + aoi][akai];
        (inc *= binom[m - 2][n - k - 1])__;
        (inc *= fpow(2, n - k - 1))__;
        ans += inc;
    }
    printf("%lld\n", ans _);
 
    return 0;
}

Submission Info

Submission Time
Task F - Solitaire
User cyand1317
Language C++14 (GCC 5.4.1)
Score 1200
Code Size 1581 Byte
Status AC
Exec Time 68 ms
Memory 124032 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:43:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
                          ^

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 68 ms 124032 KB
00_example_02.txt AC 68 ms 124032 KB
00_example_03.txt AC 68 ms 124032 KB
01.txt AC 68 ms 124032 KB
02.txt AC 68 ms 124032 KB
03.txt AC 27 ms 64128 KB
04.txt AC 68 ms 124032 KB
05.txt AC 26 ms 64128 KB
06.txt AC 68 ms 124032 KB
07.txt AC 68 ms 124032 KB
08.txt AC 68 ms 124032 KB
09.txt AC 68 ms 124032 KB
10.txt AC 68 ms 124032 KB
11.txt AC 27 ms 64128 KB
12.txt AC 68 ms 124032 KB
13.txt AC 68 ms 124032 KB
14.txt AC 68 ms 124032 KB
15.txt AC 68 ms 124032 KB
16.txt AC 68 ms 124032 KB
17.txt AC 68 ms 124032 KB
18.txt AC 68 ms 124032 KB
19.txt AC 68 ms 124032 KB
20.txt AC 68 ms 124032 KB
21.txt AC 27 ms 64128 KB
22.txt AC 27 ms 64128 KB
23.txt AC 68 ms 124032 KB