Submission #1293459


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 C - X: Yet Another Die Game
User cyand1317
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1575 Byte
Status WA
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 0 / 300
Status
WA × 2
WA × 18
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt
All 00_example_01.txt, 00_example_02.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
Case Name Status Exec Time Memory
00_example_01.txt WA 68 ms 124032 KB
00_example_02.txt WA 68 ms 124032 KB
01.txt WA 68 ms 124032 KB
02.txt WA 68 ms 124032 KB
03.txt WA 68 ms 124032 KB
04.txt WA 68 ms 124032 KB
05.txt WA 68 ms 124032 KB
06.txt WA 68 ms 124032 KB
07.txt WA 68 ms 124032 KB
08.txt WA 68 ms 124032 KB
09.txt WA 68 ms 124032 KB
10.txt WA 68 ms 124032 KB
11.txt WA 68 ms 124032 KB
12.txt WA 68 ms 124032 KB
13.txt WA 68 ms 124032 KB
14.txt WA 68 ms 124032 KB
15.txt WA 68 ms 124032 KB
16.txt WA 68 ms 124032 KB